0

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 ".

2
  • what do you want to extract from [[["text to extract"," ... or [[["text to extract",[[ ... ? Commented Mar 29, 2015 at 17:45
  • It is dynamic, what I know is that the text always ends with double quotes. Accept any character without double quotes Commented Mar 29, 2015 at 17:51

2 Answers 2

2

This Regex should work,

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

Demo

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

It uses the concept of Group capture

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! :D works fine. because the first double quote comes without backslash and the second we?
0

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]

3 Comments

Not work. result: description."]],,"en",,,[["SVM",1,
What if the text contains escaped quotation mark (\")?
when he brings is encoded in unicode quotes \u0000 because the string is an array in javascript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.