I have a buffer of data which contains some strings I want to replace, but I want to put the replacing string before and after where the "bad" string was:
Lets say the input data has the line
<entry>22<?Pub _hardspace?>AWG or larger</entry>
I want the output to be
<entry><xx>22 AWG</xx> or larger</entry>
(Yes, it is XML, and no , I am not using XML::Simple - I am fighting a different battle trying to install that!)
So, I am using this relatively simple search and replace
perl -pi -e 's/(\S+)<\?Pub \_hardspace\?\>(\S+)/<xx\>$1 $2<\/xx\>/gs'
+test
but it's coming out a little incorrect as
<xx><entry>22 AWG</xx> or larger</entry>
ie the <xx> is starting too early - I'm matching a word with the "S" so maybe that is matching '<entry>22' rather than just 22 ??
Any ideas ? The character immediately preceeding could be anything, not just '>' ...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.