Perl Regex to Process Text Input -


i have perl script imports html , converts plain text. using html::tagfilter remove html tags , working except we've run 1 issue. when html contains non-stand html tags such "caption" in example input below tags aren't being removed:

lorem ipsum dolor sit amet, consectetur adipiscing elit. etiam pulvinar, odio ut gravida fringilla, tellus mi ultrices felis, quis porta lacus sem ut lacus. vestibulum massa justo, tristique id aliquet in, dapibus eu leo. nam sapien risus, dictum et porttitor quis, egestas quis dui. ut nec nisl felis. class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.  [caption id="sample-id" align="sample-align" width="225" caption="sample caption"]<a href="http://www.domain.com/image.jpg"><img class="sample-image-class" title="sample title" src="http://www.domain.com/image.jpg" alt="sample alt" width="225" height="300" /></a>[/caption]  in hac habitasse platea dictumst. duis imperdiet bibendum dolor ut ullamcorper. suspendisse dui erat, facilisis sed aliquet non, elementum eu urna. donec non nisi vel augue gravida imperdiet sed id tortor. maecenas ullamcorper velit non dui imperdiet hendrerit. 

what need simple perl regex remove content completely. i've tried bunch of different approaches nothing seems working. i'm looking following find , remove occurrences of non-standard html tags using brackets []:

$text =~ s/[(\w)+](.*)[\/(\w)+]//g; 

i'm hoping simple exercise better @ regex am.

thanks in advance help!

you have escape brackets because have special meaning within regular expressions. assuming attributes double-quoted no double quotes inside them, following should work.

$text =~ s/\[\/?\w+(\s+\w+="[^"]*")*\s*\/?\s*\]//g; 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -