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)

demo regex

  1. positive lookahead (?=(\s+)?sentence)
  2. 1st capturing group (\s+)? ? quantifier — matches between 0 , 1 times, many times possible, giving needed (greedy)
  3. \s+ matches whitespace character (equal [\r\n\t\f\v ])
  4. + 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

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

angular - Copying node modules to wwwroot AspNetCore -