• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

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
0
rgb192
Asked:
rgb192
3 Solutions
 
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
 
tdlewisCommented:
@ozo, you're right about the order.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
käµfm³d 👽Commented:
Why even use a regex? A simple string replace should suffice. Which language are you using?
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now