• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dangling meta character '*' near index 0 (java.util.regex.PatternSyntaxException)

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello..

Am using a pattern - Pattern p1 = Pattern.compile("*(.data)"); but I get the above error..

What I want to find is all '*.data' iles from a directory..

Thanks for your help!!
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to consider picking up a good book on regex. Its a good thing to learn, as regex is an important tool.

But back to your question... A "*" means zero or more of the previous. So, a "*" as the first character doesn't make sense.

Henry
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"*" is a special character in regular expressions (as is "."); it means "zero or more matches of the preceding pattern", which is not the same as what it means when matching filenames at the command line (using those patterns is often called "globbing"). A regular expression that matches files named "*.data" would be



This means "one or more characters followed by ".data". The first dot is used in its regular expression meaning of "any character", but the second dot should match only a dot, so we've escaped it with a backslash.
 
Rakesh Rajmohan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool.. Thanks for your responses.. I tried using "[a-zA-Z]*\\.data" and it worked.. But if it had any special chars, it wasn't working.. So I tried out your ".+\\.data" and it worked like a GEM..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic