开发者

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')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜