Reputation: 1
I'm parsing data from my satellite box to receive music information to display on my iPad. One particular string I'm interested in looks like this;
"title": "\"Free Falling\""
I want to match Free Falling only so that it can be displayed. I tried
"title": "(.*)"
but it returns "\Free Falling\"
I tried negating the forward slashes [^\/]
but the when tested, the first space between Free and Falling matches the entire pattern
How do I match the words Free Falling only, without the quotes and forward slashes and retain the white space?
Upvotes: 0
Views: 2256
Reputation: 43673
If the syntax is always same and such title string starts and ends with \"
, then use a regex pattern
"title":\s*"\\"(.*)\\""
and your desired result will be in group #1
If the \"
is optional, then use
"title":\s*"(\\"|(?!\\"))(.*)\1"
and your desired result will be in group #2
Upvotes: 1
Reputation: 106455
If other entries do not have these additional \"
s around the title names and you want to be able to use one regex to match titles both with and without \"
s, you can use a regex like this:
"title": "(?:\")?([^\\"]*)
Upvotes: 0