Regular Expression change text between tags
I have some code in the following layout,i m using textcrawler to do a find and replace
<a>
Name=LineA
epsium
ask
answer
line=10
color=red
</a>
<a>
Name=LineB
Color=Blue
</a>
...
Now the question is what regular expression i need to use so as to remove 开发者_运维知识库the second block of code between <a> and </a>
<a>(\s*?Name\=LineB[\S\s]*?)</a>
It captures all text between and including the <a></a>
tags that starts with the text Name=LineB
.
In Perl, I'll do :
$str =~ s~^(.*?<a>.*?</a>.*?)<a>.*?</a>(.*)$~${1}New text$2~s;
the first group contains everything before the second block <a></a>
and the second group everything after.
In php:
$str = preg_replace('~^(.*?<a>.*?</a>.*?)<a>.*?</a>(.*)$~', "${1}New text$2", $str);
preg_replace("/<body>([\s\S]*.*)<\/body>/",$replace,$origional);
this will replace whole content between body tags.
精彩评论