2011-02-05 6 views
1

기호를 HTML 태그로 바꾸고 싶습니다. 예를 들어 : ":"다른 문자 닫는 일치하는지 확인기호를 HTML 태그로 바꾸기

This :is: some :text: that could also look :a: bit :different:. 

는 당신이 밖으로 변경할 수 있습니다 \1를 사용

This <span id="selected">is</span> some <span id="selected">text</span> that could also look <span id="selected">a</span> bit <span id="selected">different</span>. 

답변

1
$str = "This :is: some :text: that could also look :a: bit :different:"; 
$str =~ s/:(\w+):/<span id='selected'>$1<\/span>/g; 
print $str; 
2
$s =~ s{:([^:]+):}{<span id="selected">$1</span>}g; 
관련 문제