• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

regular expressions "\\*"

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I am new to regular expressions. I would really appreciate if someone could shed some light on why the below matcher fails. In order to use special char, I think the use "\\" is necessary, please correct if I am wrong.

Pattern grpP = Pattern.compile("\\*");
Matcher grpM = grpP.matcher("*");

boolean match = grpM.matches();

MATCH IS FALSE, SHOULDN'T THIS BE TRUE.

Thanks & Regards,
Pinal
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pinal,

Don't really know what to say here - I just copied and pased that code into a class and it runs fine with match being true.

So you're right to expect match to be true, but I don't see why it doesn't for you.
 
Pinal N Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pete,

As soon as you replied, I double checked the class and turns out I was testing a different overloaded method which had different pattern.

thanks for you help.

Pinal
 
Always look on the bright side of life. At least this ad is really tiny:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic