regex text to xml

Text: "Business & Industrial > Heavy Machinery > Chippers"
 
XML: Business & Industrial > Heavy Machinery > Chippers


given
"Business & Industrial > Heavy Machinery > Chippers"
 
want this as output
Business & Industrial > Heavy Machinery > Chippers
LVL 1
rgb192Asked:
Who is Participating?
 
käµfm³d 👽Commented:
Why even use a regex? A simple string replace should suffice. Which language are you using?
0
 
tdlewisCommented:
In Perl this would be:
$text =~ s/</&lt;/g;
$text =~ s/>/&gt;/g;
$text =~ s/&/&amp;/g;

Note that you must replace < and > before &.
0
 
ozoCommented:
I'd do that in the opposite order,
 s/&/&amp;/g, s/</&lt;/g, s/>/&gt;/g for $text;
or replace them all at once as
$text =~ s/([<>&])/&${{'<'=>'lt','>'=>'gt','&'=>'amp'}}{$1};/g;
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
tdlewisCommented:
@ozo, you're right about the order.
0
 
rgb192Author Commented:
I am using php
0
 
rgb192Author Commented:
thank you
I am using php and have an updated question of how to do this in php

http://www.experts-exchange.com/Programming/Languages/Regular_Expressions/Q_27852846.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.