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

[675 byte] By [marcus2376a] at [2007-11-27 6:04:52]
# 1
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 :)
hunter9000a at 2007-7-12 16:49:44 > top of Java-index,Java Essentials,Java Programming...
# 2

> 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]

Hippolytea at 2007-7-12 16:49:44 > top of Java-index,Java Essentials,Java Programming...
# 3
Your regex is greedy, you need to make it reluctant to collect '' chars -\\"([^\\"]*)\\"and you need to use matcher.find().Message was edited by: sabre150
sabre150a at 2007-7-12 16:49:44 > top of Java-index,Java Essentials,Java Programming...
# 4
I am using a matcher:Pattern p = Pattern.compile(regex);Matcher m = p.matcher(line);where regex is " SRCH base=\"(.*)\""
marcus2376a at 2007-7-12 16:49:44 > top of Java-index,Java Essentials,Java Programming...
# 5
That regexp you're using wouldn't work in Perl either. It's doing greedy matching and you should be using reluctant:" SRCH base=\"(.*?)\" "
paulcwa at 2007-7-12 16:49:44 > top of Java-index,Java Essentials,Java Programming...
# 6
That did it! Thanks Sabre150! FYI - I did have to remove the extra backslashes for it to compile, but it worked! " SRCH base=\"([^\"]*)\""
marcus2376a at 2007-7-12 16:49:44 > top of Java-index,Java Essentials,Java Programming...
# 7
Hmmm... I thought the Bat Signal would get through to uncle_alice
Hippolytea at 2007-7-12 16:49:44 > top of Java-index,Java Essentials,Java Programming...
# 8

> 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!

sabre150a at 2007-7-12 16:49:44 > top of Java-index,Java Essentials,Java Programming...
# 9
Sorry, the Batmobile had a flat tire, and Alfred forgot to restock my utility belt with Fix-A-Flat. (You wouldn't believe how long it takes Big-O Tires to get those things delivered!)
uncle_alicea at 2007-7-12 16:49:44 > top of Java-index,Java Essentials,Java Programming...