extracting string inside double quote
Hi,
In perl this is really easy, but I can't get it to work correclt in java. I'm trying to extract a string that is in double quotes following a keyword...
String:SRCH base="o=answer" filter="me" attrs=ALL
I want to extract the first quoted value after "SRCH base="
In perl I used:/ SRCH base=\"(.*)\" /i
In java I'm using: " SRCH base=\"(.*)\" "
The problem is that it doesn't stop after hitting the second quote. So I get this result:
o=answer" filter="me
Notice that it stopped matching after hitting the third quote.Weird.
I know this is probably really simple, but I'm stumped.
Thanks,
Mark
I guess if you wrote a regex that matches any string that starts with ", ends with ", and has anything in between you could use a Matcher to find each occurrence, but I don't regex enough to write it :)
> I guess if you wrote a regex that matches any string
> that starts with ", ends with ", and has anything in
> between you could use a Matcher to find each
> occurrence, but I don't regex enough to write it :)
[url #" style="display: block; background-image: url('http://www.shanghaiist.com/attachments/shang_neil/bat-signal-edit.jpg'); width: 325px; height: 217px] [/url]
> That did it! Thanks Sabre150!
>
> FYI - I did have to remove the extra backslashes for
> it to compile, but it worked!
>
> " SRCH base=\"([^\"]*)\""
:-( sorry about the extra \s! I spent too much time on the regex and not enough on the escaping!