Thursday, 22 August 2013

PHP regex, how can I make my regex only return one group?

PHP regex, how can I make my regex only return one group?

I have tried the non capturing group option ?:
Here is my data:
hello:"abcdefg"},"other stuff
Here is my regex:
/hello:"(.*?)"}/
Here is what it returns:
Array
(
[0] => Array
(
[0] => hello:"abcdefg"}
)
[1] => Array
(
[0] => abcdefg
)
)
I wonder, how can I make it so that [0] => abdefg and that [1] => doesnt
exist?
Is there any way to do this? I feel like it would be much cleaner and
improve my performance. I understand that regex is simply doing what I
told it to do, that is showing me the whole string that it found, and the
group inside the string. But how can I make it only return abcdefg, and
nothing more? Is this possible to do?
Thanks.
EDIT: I am using the regex on a website that says it uses perl regex. I am
not actually using the perl interpreter
EDIT Again: apparently I misread the website. It is indeed using PHP, and
it is calling it with this function: preg_match_all('/hello:"(.*?)"}/',
'hello:"abcdefg"},"other stuff', $arr, PREG_PATTERN_ORDER);
I apologize for this error, I fixed the tags.
EDIT Again 2: This is the website
http://www.solmetra.com/scripts/regex/index.php

No comments:

Post a Comment