Question

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>

Was it helpful?

Solution

<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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top