Reputation:
Is it possible to create a single regexp to replace < and > with their entity equivalents in Komodo Edit?
s/<|>/<|>/
Upvotes: 1
Views: 2226
Reputation: 24637
In Komodo Edit 5.x, use the moreKomodo extension to save the following find/replace regex search:
Find:
<([^>]*)>([^<]*)<([^>]*)>
Replace:
<\1>\2<\3>
Upvotes: 0
Reputation:
Thanks everyone. I was looking for something I could use in Komodo Edit, so variables and conditional statements were not an option. Here is the best solution I found, which was based on a Sed tutorial at IBM Developerworks:
s/<([^>]*)>([^<]*)<([^>]*)>/<\1>\2<\3>/
Upvotes: 0
Reputation: 91068
It is easy in to do this in just about any language without using regex:
PHP:
$xml = str_replace(array('>', '<'), array('>','<'), $xml);
Python:
xml = xml.replace('>', '>').replace('<','<');
etc.
Upvotes: 1
Reputation: 9332
It depends on the language you are using. In Perl, you could do:
s/([<>])/$1 eq '<' ? '<' : '>'/ge
Other languages usually allow you to provide a match callback function that returns a replacement string. To wit: In C#, you can do this:
Regex.Replace("<", "([<>])", x => x.Value == "<" ? "<" : ">")
Upvotes: 0
Reputation: 2740
You could use a hash-variable, something like:
my %data;
$data{"<"} = '<';
$data{">"} = '>';
s/(<|>)/$data{$1}/g;
Upvotes: 0
Reputation: 272417
I'm guessing that you may have to convert &
to &
and so on.
If this is the case there's most likely a library or function in whichever language/platform you're using (e.g. in Java check out StringEscapeUtils). Indicate which language you're using and someone here will no doubt point you to something appropriate.
Upvotes: 2