开发者

Simple javascript regex help needed

I have an regex expression:

\[quote\](.*?)\[\/quote\]

and it matches correctly between [quote]example[/quote] but it does not find a match for:

[quote]
example

[/quote]
开发者_JAVA技巧

how can I change the regex so it finds a match in the latter case too? *And keeps the format (multiple lines)

Thanks.


Add [\r\n]* to the regular expressiuon

\[quote\](.*?)\[\r\n]*[\/quote\]


The problem is that in JavaScript the . does not match a new line (and this cannot be changed unlike in other languages where you might use the s modifier). So the following should work:

\[quote\]([\s\S]*?)\[\/quote\]

\s will match every whitespace character (including new lines) and \S will match every non-whitespace character - together [\s\S] matches every character including new lines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜