I have the following String:
"Something:string(lower-case) anything Somethingb:numbers开发者_高级运维"
I am trying to get the char after Something and the numbers after Somethingb with preg_replace.
Also, sometimes the string will be just the first part:
"Something char anything"
So what I need is an outcome like this using preg_replace:
"string(lowercase) , numbers"
or just
"string(lowercase)"
if the Something b is not in the string.
Any idea would be much appreciated.
Thanks
Here is regex for first case:
/Something:([a-z]+).*?Somethingb:(\d+)/
and replace
$1 , $2
also you can pass &$count parameter to know if replace was successful
In second case do you want "Something char anything" to become "something char anything"? if this is so that you can just do strtolower($string) if $count == 0
精彩评论