2012-05-03 1 views
1

HTML에 액세스 할 수 없으며 원시 텍스트 만 있습니다. INFO 및 ENDINFO와 같은 원시 텍스트에서 단어를 찾아 컨텐츠 주위에 div를 래핑하는 데 사용할 수 있습니까?찾기 word 및 랩 div

<div> 
content content content content content 

INFO 
Information content information content 

ENDINFO 
</div> 

<div> 
content content content content content 

    <div class="INFO"> 
    Information content information content 

    </div> 
</div> 

도움이 될 것입니다. 감사.

+0

안녕하세요. 단어를 찾으려면'.find'를 사용하고 단어를 찾을 때는'.prepend'를 사용하십시오. http://api.jquery.com/prepend/이 도움이 되길 바랍니다, 건배! –

+0

이상한 상황. 이것은이 문자열을 생성하는 전처리 과정을 실제로보고 있어야하는 인스턴스와 같습니다. – ckaufman

답변

1

어때?

<div id="content"> 
content content content content content 

INFO 
Information content information content 

ENDINFO 
</div> 

<div> 
content content content content content 

    <div class="INFO"> 
    Information content information content 

    </div> 
</div> 

<script> 
$(document)ready(function(){ 
    var content = $('#content').html(); 
    var regex = /INFO.*ENDINFO/gi; 
    var info = content.match(regex); 

    $('.INFO').html(info); 
}); 
</script> 
+0

정말 고맙습니다. 나는 정규식을 사용한 적이 없다. 감사! 아주 잘 작동합니다. – uriah