File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Regex question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regex question" Watch "Regex question" New topic

Regex question

Max Power
Ranch Hand

Joined: May 10, 2004
Posts: 47
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?
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
this seems to do it:

David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
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 ]
I agree. Here's the link:
subject: Regex question
It's not a secret anymore!