Find string with RegEx
I want to find a string in text for example Hello World i开发者_Python百科n
"Hello World ,hello World, Hello
World"
I want to replace Hello World with Rock
"Rock ,Rock, Rock"
Using perl
$ perl -pe 'BEGIN{undef $/;} s/[hH]ello.*?World/Rock/smg' input
"Rock ,Rock, Rock
"
echo preg_replace('/[(H|h)ello World]+/','Rock','Hello World ,hello World, Hello World')
精彩评论