RegEx javascript - Need assistance limiting search -
this question has answer here:
- my regex matching much. how make stop? 4 answers
- why regex constructors need double escaped? 4 answers
i wish search/replace support escalations matrix below email signatures, regex selecting far much.
the example text has 3 "support escalations" blurbs. wish remove/colorize/whatever three. regex selecting text in between, starting point in first 1 ending point in last one. (problem easiest see in regex101 demo, below.)
var regex = new regexp('support escalations*[\s\s]*level iv.*', 'gi'); var txt = $('#blurb').html(); txt = txt.replace(regex, '=-=-=-=-=-=-=-=-=-=-=<br>'); $('#blurb').html(txt); //alert(txt);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="blurb"> support escalations<br> level i: noc technician - support@example.com | o: 989.571.1000<br> level ii: manager, network & eng operations, william tell - wchen@example.com | o: 212.777.9999 x123 | m: 989.265.9876<br> level iii: vice president, operations, blaise pascal - blaisep@example.com | o: 212.777.9999 x234 | m: 343.301.2822 <br> level iv: chief operating officer: bf skinner - bskinner@example.com | o: 212.777.9999 x345 | m: 343.337.7775<br> <br> <br> <br> from: example tech support <br> sent: monday, august 7, 2017 3:27 pm<br> to: example tech support <support@example.com>; 'nocdata@sample.com' <nocdata@sample.com><br> subject: re: 81434 | win - reparian riverfront - eoc 10mb - partial impact<br> <br> sample support,<br> <br> please advised loops have been repaired customer , @ full bandiwdth.<br> stable, close ticket out.<br> <br> please let know if have questions.<br> <br> thank you,<br> <br> john doe<br> example, inc. <br> <br> office: 212.777.9999 x295<br> jdoe@example.com| transbeam.com <br> <br> support escalations<br> level i: noc technician - support@example.com | o: 989.571.1000<br> level ii: manager, network & eng operations, william tell - wchen@example.com | o: 212.777.9999 x123 | m: 989.265.9876<br> level iii: vice president, operations, blaise pascal - blaisep@example.com | o: 212.777.9999 x234 | m: 343.301.2822 <br> level iv: chief operating officer: bf skinner - bskinner@example.com | o: 212.777.9999 x345 | m: 343.337.7775<br> <br> <br> <br> from: example tech support <br> sent: thursday, august 3, 2017 9:24 am<br> to: example tech support <support@example.com>; 'nocdata@sample.com' <nocdata@sample.com><br> subject: re: 81434 | win - reparian riverfront - eoc 10mb - partial impact<br> <br> correction. commit on new ticket (loop 4) 08/16. apologies error.<br> <br> -------------------------------------<br> judy garland<br> noc technician<br> <br> from: example tech support <br> sent: thursday, august 03, 2017 9:22 am<br> to: 'nocdata@sample.com'<br> cc: example tech support<br> subject: 81434 | win - reparian riverfront - eoc 10mb - partial impact<br> <br> hello,<br> <br> update regarding results of ilec dispatch prem date. ilec technician repaired loop down (loop 3), loop (loop 4) developed problem while there , bouncing. loop 4 has been removed efm-group prevent affecting circuit , ticket opened ilec repair (commit 08/14).<br> <br> @ time, 10mb circuit @ 9.8mbps on 3 loops.<br> <br> <br> if have further questions, comments or concerns regarding message, please contact example noc support documented below.<br> <br> thank you,<br> <br> -------------------------------------<br> judy garland<br> noc technician<br> <br> transbeam.com<br> <br> =======================================================================<br> support escalations<br> level i: noc technician - support@example.com | o: 989.571.1000<br> level ii: manager, network operations, william tell - wchen@example.com | o: 212.777.9999 x123 | m: 989.265.9876<br> level iii: vice president, operations, blaise pascal - blaisep@example.com | o: 212.777.9999 x234 | m: 343.301.2822 <br> level iv: chief operating officer: bf skinner - bskinner@example.com | o: 212.777.9999 x345 | m: 343.337.7775<br> </div>
you need use lazy quantifier in regex:
/support escalations*[\s\s]*?level iv.*/gi // --^--
a lazy quantifier matches between 0 , unlimited times, few times possible, expanding needed. see regex101.
Comments
Post a Comment