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
Post a Comment