필터 지우기
필터 지우기

regexprep / doesnt work backwards

조회 수: 4 (최근 30일)
Max Müller
Max Müller 2014년 9월 9일
댓글: Max Müller 2014년 9월 10일
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 ?

채택된 답변

Guillaume
Guillaume 2014년 9월 9일
편집: Guillaume 2014년 9월 9일
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
Max Müller
Max Müller 2014년 9월 10일
Thank you....works perfect

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by