regex - How can I get "first" and "second" with a JavaScript regular expression in "This is my first sentence. This is my second sentence."? -
how can "first" , "second" javascript regular expression in "this first sentence. second sentence."
you can try here on website regular website
for example in python "(?<=(this is)).*?(?=sentence)",this work;but dont know how write javascript
try pattern \w+(?=(\s+)?sentence)
- positive lookahead
(?=(\s+)?sentence) - 1st capturing group
(\s+)??quantifier — matches between 0 , 1 times, many times possible, giving needed (greedy) \s+matches whitespace character (equal [\r\n\t\f\v ])+quantifier — matches between 1 , unlimited times, many times possible, giving needed (greedy) sentence matches characters sentence literally (case insensitive)
var = 'this first sentence.this second sentence' console.log(a.match(/\w+(?=(\s+)?sentence)/ig)) updated regex while loop , push value array
var s = '</span><span>wanna-string-a</span></a></span><span>wanna-string-b</span></a></span><span>wanna-string-c</span></a>'; var qualityregex = /<span>(.*?)<\/span>/g; var matches; var qualities = []; while (matches = qualityregex.exec(s)) { qualities.push(matches[1]); } console.log(qualities)
Comments
Post a Comment