php - Return first outer result from a string, using regular expressions -


i have following string:

"{my {formatted {hi|hello}|formate{hi|hello} }  {option 1|option 2|option 3}}"; 

i want find result in-between "{" , "}" brackets.

also result should outer layer, not {hi|hello} but:

"my {formatted {hi|hello}|formate{hi|hello} }  {option 1|option 2|option 3}" 

/^{(.*)}$/ remove first , last { , }

used via $var = preg_replace('/^{(.*)}$/', '$1', $your_text);

that particularly can made basic string operations too, advance regex /^[^{]*{(.*)}[^{]*$/ let put chars in front of desired string , after it. again, can done string operations itself, using substr , strrpos.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -