javascript - How to match space, newline in regexp -


this question has answer here:

string content

<head>     <meta charset="utf-8">     <title></title>     <!--@require a.css-->     <!--@require bower/jquery-->     <!--@require /build/bundle-->     <!--         @require bootstrap         @require bootstrap.css         @require bootstrap.font     --> </head> 

js

var content = ...; var reg = /<!--[\s\t\n]*?@require (.+?)[\s\t\n]*?-->/g; var r; while((r = reg.exec(content)) != null) {   console.log(r[1]); } 

output

a.css bower/jquery /build/bundle 

it's not match last block, miss in reg expression.

(dot). matches character except newline , that's why last string not matching. can use [\s\s]* or [^] matching character. ( ref : matching multiline patterns )

var content = `<head>      <meta charset="utf-8">      <title></title>      <!--@require a.css-->      <!--@require bower/jquery-->      <!--@require /build/bundle-->      <!--          @require bootstrap          @require bootstrap.css          @require bootstrap.font      -->  </head>`;  var reg = /<!--[\s\t\n]*?@require ([\s\s]+?)[\s\t\n]*?-->/g;  var r;  while ((r = reg.exec(content)) != null) {    console.log(r[1]);  }


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -