MATLAB Answers

regexprep / doesnt work backwards

2 views (last 30 days)
Max Müller
Max Müller on 9 Sep 2014
Commented: Max Müller on 10 Sep 2014
Hey Guys, I am using this code
Text = '<HTML><FONT color="0000FF">Used Amplification</FONT></HTML>' % from a listbox
Search = '</FONT></HTML> '
Add = '(hidden)</FONT></HTML> '
regexprep(Text,Search,Add)
to create this code
<HTML><FONT color="0000FF">Used Amplification(Hidden)</FONT></HTML>
Now I want to get back the old Code so i use regexprep(Text,Add,Search) but it doesnt work ?

  0 Comments

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 9 Sep 2014
Edited: Guillaume on 9 Sep 2014
You're not actually using regular expressions. Your search pattern is just a plain string, so you'd be better off using strrep.
The reason it doesn't work with Add as a search pattern is that the ( character has a special meaning in regexes so to match a bracket you need to escape it with a backslash, either manually or using regexptranslate:
regexprep(Text, regexptranslate('escape', Add), Search)
But as I said
strrep(Text, Add, Search)
would work just as well and will probably be faster.

  1 Comment

Max Müller
Max Müller on 10 Sep 2014
Thank you....works perfect

Sign in to comment.

More Answers (0)

Sign in to answer this question.