简体   繁体   English

正则表达式和多个字符串

[英]Regular Expressions and multiple strings

I'm trying to create a regular expression that matches EXACTLY the following set of strings, I'm super new to RegExp and don't know how to register line breaks: 我正在尝试创建一个与以下字符串完全匹配的正则表达式,我是RegExp的新手,并且不知道如何注册换行符:

fun  
ab  
acb         
accb  
acccb  
accccb  
....

If you are trying to include fun as one of the options: 如果您尝试将fun作为选项之一:

 function check(string) { return /^(?:fun|ac*b)$/.test(string) } console.log([ 'fun', //=> true 'ab', //=> true 'acb', //=> true 'accb', //=> true 'acccb', //=> true 'accccb', //=> true 'abc', //=> false 'ccccb', //=> false 'acccb ' //=> false (note the extra space) ].map(check)) 

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

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