+ 14
match method that get characters include multiple lines beween two words in javascript
i want to get all characters between 2 words include multiple lines, i don't find any trouble at: var string="this strings have no trouble"; var string2=string.match("stri(.*)no"); alert(string2[1]);//output ngs have //no problem, works as i want but the trouble at var string="oh no, i am dont want it /n occurs, this strings have a trouble"; var string2=string.match("dont(.*)strings"); alert(string2[1]);//output want it //I get the problem what i want is the output is: want it /n occurs, this
2 ответов
+ 1
First you need to remove the /n:
var t = 'abc \n def';
alert(t);
alert(t.replace(/\r?\n|\r/g,''));
I hope it helps :)
+ 2
Instead of using string.match("dont(.*)strings");
you can use this
string.match(/dont([\s\S]*)strings/g);