Regex find and replace between <div class="customclass"> and </div> tag -


i cant find anywhere working regex expression find , replace text between div tags

so there html want select between <div class="info"> , </div> tag , replace other texts

<div class="extrauserinfo">         <p>hello world! sample text</p>         <javascript>.......blah blah blah etc etc </div> 

and replace with

my custom text codes <tags> asdasd asdasdasdasdasd</tags> 

so

<div class="extrauserinfo">         custom text codes <tags> asdasd asdasdasdasdasd</tags> </div> 

here refiddle code there , can see want replace whole bunch of codes between , tag

http://refiddle.com/1h6j

hope mean :)

if there's no nesting, plain match non-greedy (lazy)

(?s)<div class="extrauserinfo">.*?</div> 
  • .*? matches amount of character (as few possible) meet </div>
  • used s modifier making dot match newlines too.

edit: here javascript-version without s modifier

/<div class="extrauserinfo">[\s\s]*?<\/div>/g 

and replace new content:

<div class="extrauserinfo">my custom...</div> 

see example @ regex101; regex faq


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -