ssmithstone
ssmithstone

Reputation: 1209

Groovy Regular matching everything between quotes

I have this regex

regex = ~/\"([^"]*)\"/

so Im looking for all text between quotes now i have the following string

options = 'a:2:{s:10:"Print Type";s:8:"New Book";s:8:"Template";s:9:"See Notes";}'

however doing

regex.matcher(options).matches() => false

should this not be true, and shouldn't I have 4 groups

Upvotes: 2

Views: 1681

Answers (1)

Tim Pietzcker
Tim Pietzcker

Reputation: 336468

The matcher() method tries to match the entire string with the regex which fails.

See this tutorial for more info.

I don't know Groovy, but it looks like the following should work:

def mymatch = 'a:2:{s:10:"Print Type";s:8:"New Book";s:8:"Template";s:9:"See Notes";}' =~ /"([^"]*)"/

Now mymatch.each { println it[1] } should print all the matches.

Upvotes: 3

Related Questions