Albz
Albz

Reputation: 2030

Regex isolate specific string between double quotes

I have this string:

*"TEST_START" List of 4 $ test : Named num 0.983 ..- attr(, "names")= chr "W" $ p.value : num 0.975 $ method : chr "This is the test name" $ data.name: chr "x" - attr(, "class")= chr "htest" [1]*

I'm trying to write a regex that could isolate just the following substring withing double quotes: This is the test name

At the moment I made this regex:

method\s:\schr\s"([^"]*)"

It isolates a subset of the string. However I'd need to match just the aforementioned substring (This is the test name).

Upvotes: 1

Views: 371

Answers (2)

John Woo
John Woo

Reputation: 263713

Try this,

(?<=method\s:\schr\s").*?(?=")

See Lookahead and Lookbehind Zero-Width Assertions.

RegexBuddy Screenshot

enter image description here

Upvotes: 3

zeffii
zeffii

Reputation: 544

chr "(.*?)" \$ , then pick the second match. Works if you can be confident about how consistent the input string is. But be aware that not all implementations of regex are 100% identical. You might want to be clear about what language you are regex-ing in.

Upvotes: 1

Related Questions