Taylor Swift Taylor Swift - 7 months ago 9
PHP Question

Everything between "[reply]" and extract the reply number

Please take a look at the following situation below.

[reply="292"] Text Here [/reply]


What I am trying to get is the number between the quotations in
reply="NUMBERS"
. I want to extract that to one variable and the text between
[reply="NUMBER"] this text here [/reply]
to another variable.

So for this example:

[reply="292"] Text Here [/reply]


I want to extract the reply number:
292
and the text between the
reply
tags:
Text here
.

I have tried this:

\[reply\=\"]([A-Z]\w)\[\/reply]


But this only works until the
reply
tag, doesn't work after that. How can I go about doing this?

Answer

I left generic (. *), but you can specify a type like decimal (\d+).

php:

$s = '[reply="292"] Text Here [/reply]';
$expr = '/\[reply=\"(.*)\"\](.*)\[\/reply\]/';
if(preg_match($expr,$s,$r)){
    var_dump($r);
}

javascript:

s = '[reply="292"] Text Here [/reply]'
s.match(/\[reply=\"(.*)\"\](.*)\[\/reply\]/)
//["[reply="292"] Text Here [/reply]", "292", " Text Here "]