javascript - find class name by regex -
i want class match key regex, when search btn, :
<div class="btn"> // match <div class="span4"> // not match <div class='btnbtn-success'> // not match </div> <div class=' bbtn '> // not match </div> <div class=' bbtn '> // not match </div> <div class=' b btn '> / match </div> <div class='cbbtn '> // not match </div> <div class='btn '> // match </div> <div class=' bbtn '> // not match </div> <div class=' btn'> // match </div> <div class=" btn "> // match </div> <div class='hello btn '> // match </div> <div class=" btn "> // match </div> <div class=" btn hello"> // match </div> <div class=" btnaa hello"> // not match </div> <div class=" hello btn hello"> // match </div> <div class=" hello btn"> // match </div> <div class=" hello btn hello"> // match </div> <div class=" hello btn "> // match </div> <div class=" btna "> // not match </div> <div class=" btna-success "> // not match </div> </div> </div>
what best regex find btn class name in code?
not sure if want divs or class names. ll give shot suppose:
/(.*[\s+\"\']btn[\s+\"\'].*)/g
demo here : http://regex101.com/r/fd6fc4
feel free ask query or clarifications
updated answer
i editing regex make bit complex 1 cover cases people have mentioned in comments. thank people comments in improving it.
improved regex : /(?=<[^>]+(?=[\s+\"\']btn[\s+\"\']).+)([^>]+>)/g
demo here : http://regex101.com/r/qh2hz2
Comments
Post a Comment