Link to home
Start Free TrialLog in
Avatar of mikeysmailbox1
mikeysmailbox1

asked on

Perl replace & in xml data

Hi

I need to replace and & but if there is a & or " do not replace the &
Not sure how to do this.

Thanks

Mike
ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
s/\s+\&\s+/ and /g;

What are you replacing it with, the pattern match searches for " & "
You have to account for ..

Please post an example of data sample.

&

If solving before and after is important enclosing \s+ in percentages will assign it when match to $1 and $2
s/(\s+)\&(\s+)/$1replacement$2/g
The first s/ tells this is a find/replace
The ending /g tells it find replace all occurances. Without this, the find/replace will only perform one replacement per line.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Two people submitted slightly different solutions and the OP never responded.