regex - Including character that was used in the pattern search in the match -


i have string:

[?q]this test[?p] <br> [?q]this test<random_tag> 

i want text between [?q] , [?p] or [?q] , <. want keep < in match results. have regex:

\[\?q\](.*?)(?:\[\?p\]|<) 

but if replace of first group aaa, this:

aaa <br> aaarandom_tag> 

i want this:

aaa <br> aaa<random_tag> 

regex link demonstration

try

change regex /\[\?q\](.*?)(?:\[\?p\]|(?=<))/g or try other regex have mentioned below

var str = '[?q]this test[?p]\n<br>\n[?q]this test<random_tag>'; var res = str.replace(/(\[\?q\].*?\[\?p\]|\[\?q\].*?(?=<))/g, 'aaa'); console.log(res); 

i have used positive lookahead check if value followed <

link demo


Comments

  1. Best eCOGRA Sportsbook Review & Welcome Bonus 2021 - CA
    Looking for https://vannienailor4166blog.blogspot.com/ an eCOGRA Sportsbook Bonus? https://deccasino.com/review/merit-casino/ At this eCOGRA ventureberg.com/ Sportsbook review, we're talking about https://febcasino.com/review/merit-casino/ a https://septcasino.com/review/merit-casino/ variety of ECCOGRA sportsbook promotions.

    ReplyDelete

Post a Comment

Popular posts from this blog

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -