• 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

Java Regexp matching - not working in loop

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

I am trying to perform a java regexp matching as follows:
I have an xml file which I parse to instantiate a rule object. The xml file also contains a regular expression, which is a field in the Rule object. Rule object is as follows :


Sample input value for str in one iteration is 'This is our house and we have a dog'
Sample regExp is '\\bour\\b'
Issue: m.find() - never returns true. I have been breaking my head over this for quite sometime now and not been able to find a solution. Please help.

Thanks in advance !!


[HENRY: Added Code Tags]
 
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

cyber aishu wrote:
Sample input value for str in one iteration is 'This is our house and we have a dog'
Sample regExp is '\\bour\\b'



Wrote a quick sample app using your test data and your code (with some syntax errors fixed), and it works.... works for me.

BTW, here's the code:


Henry
 
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the regular expression is being read from an XML file, there's no need to escape the backslash. That's only needed for Java string literals. So just try \bour\b.
 
cyber aishu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Matthew and Henry !!

@ Mathew: You are a life saviour !! That was the issue. I corrected my regexp to \bour\b and it worked fine !!
reply
    Bookmark Topic Watch Topic
  • New Topic