Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex question

 
Max Power
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i am trying to build a regex that matches this string:

something[\^]something or something\^something

i tried something like this: .*(\\[)?\\^(\\])?.* but thats not working....

any ideas?
thanks
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this seems to do it:

output:
true
true
false
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ray Stojonic:
this seems to do it:
String regex = ".*\\[?\\\\\\^\\]?.*";
Note that this will also matchandIf that's not cool, tryI haven't tried it though, but it seems reasonable given Ray's test cases.
[ November 08, 2004: Message edited by: David Harkness ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic