简体   繁体   English

Javascript正则表达式,匹配包含在方括号中

[英]Javascript regex, match contains in brackets

I have done this regex yet. 我已经完成了此正则表达式。

[\<jobjob].*|\s*[jobjob\>]

I need to match all these examples: 我需要匹配所有这些示例:

<jobjob fruits.forEach((fruit) => {
    <h1>fruit</h1>
}); jobjob>
<jobjob
fruits.forEach((fruit) => {
    <h1>fruit</h1>
});
jobjob>
<jobjobfruits.forEach((fruit) => {<h1>fruit</h1>});jobjob>
<jobjob fruits.forEach((fruit) => {
    <h1>fruit</h1>
}); jobjob>
<jobjob fruits.forEach((fruit) => { <h1>fruit</h1> }); jobjob>

I matched just last two and part of first two. 我只匹配了后两个和前两个的一部分。

What I do wrong? 我做错了什么?

Have you tried str.match(/<jobjob.*?jobjob>/s) ? 您是否尝试过str.match(/<jobjob.*?jobjob>/s)吗?

/s means that . /s表示. matches also newlines 匹配换行符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM