OK, thank you, it works!
The fact that I can't check if the parens exists in string and catch the words in the same regexp was suprising for me. I'm trying to port some regular expressions from .NET to PHP. In .NET it is possible to catch all the words in a single
match call.
I have another issue now. Is
d11wtq said , I can use the
Code: Select all
(preg_match('/^\(.*?\)$/', $string))
code to check if string contains starting and ending parens. Actually I'm trying to catch not just the words, but a key-value pairs enclosed in the parens, like (key1="value1", key2="value2", key3="value3"). I wrote the regular expression for extracting these pairs and it works OK (thank to your forum). The problem now is in checking that the whole string meets the following format: (key1="value1", key2="value2", key3="value3"), in case then it can contain the parenthesis enclosed in quotes: (key1=")"). Currently I'm using the following code for the first check:
Code: Select all
if (preg_match('/\([^\)]*\)/', $string, $matches ))
{
$string = $matches[0];
/* extracting key-value pairs from the $string */
}
It works OK, but it stops if the parens included to the value part of any key-value pairs. May you please advice me anything?
Thank you.