• Post Reply Bookmark Topic Watch Topic
  • New Topic

String. match functionality  RSS feed

 
komal sutaria
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I am using match functionality of String.

I have written regex for indentifying following format data.

(A or B) and (C or D)
or
(a OR b) and (c OR w) and (d OR m)
but it does not work.
Can any one suggest why it does not work ?

if(!expression.matches(" \\s? [\\(\\w\\W\\s]+ [or|OR] [\\)\\w\\W\\s]+ [and|AND] [\\(\\w\\W\\s]+ [or|OR] [\\)\\w\\W\\s]+ \\s?")){
System.out.println("Please enter expression correctly");

}
Thanks,
Komal Sutaria
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plese check that you have quoted the code correctly with ctrl-C ctrl-V. The code you have quoted appears to have unbalanced [] and () in.
[ May 23, 2008: Message edited by: Campbell Ritchie ]
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to have a few misconceptions about how regexes work, especially square brackets (character classes). Try this regex:
And read this: http://www.regular-expressions.info/charclass.html

Correction: I forgot to add the "(?i)" at the beginning, which is why "(or|OR)" and "(and|AND)" are not needed.
[ May 25, 2008: Message edited by: Alan Moore ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!