Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 23928
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 !!
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic