e-info128
e-info128

Reputation: 4092

php Matching javascript value

I'm attempting to run preg_match to extract the text attribute from the first value in an javascript code.

preg_match('/^\[\[\["(.*)"/i', $data, $matches, PREG_OFFSET_CAPTURE);

from

[[["text to extract"," ...

or

[[["text to extract",[[ ...

matches much text: text to extract",["...

Need onli from [[[" to next ".

Upvotes: 0

Views: 40

Answers (2)

apgp88
apgp88

Reputation: 995

This Regex should work,

\[\[\["(.*?)"

Demo

It is capturing text to extract from [[["text to extract"," ...

It uses the concept of Group capture

Upvotes: 2

Constantino
Constantino

Reputation: 81

Looks like you are almost there. Just adding the comma to the regex:

preg_match('/^\[\[\["(.*)",.*/i', $data, $matches, PREG_OFFSET_CAPTURE);

And now "text to extract" is in $matches[1][0]

Upvotes: 0

Related Questions