Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

javascript - 有关此RegExp \ b [alpahbet] {number} \ w +的问题(A question about this RegExp [alpahbet]{number}w+)

My RegExp is \b[alpahbet]{number}\w+ ( with global option )(我的RegExp是\ b [alpahbet] {number} \ w +( 带有全局选项 ))

For example)(例如)) 1. \b[EWZFKXRIVM]{9}\w+ called regA(1. \b[EWZFKXRIVM]{9}\w+称为regA) 2. \b[KVEWZRXIMA]{9}\w+ called regB(2. \b[KVEWZRXIMA]{9}\w+称为regB) the total string i want to try to match is EWZFKXRIVM, KVEWZRXIMA, FAMITWEPJQ, DOXEAUZJKF(我想尝试匹配的总字符串是EWZFKXRIVM, KVEWZRXIMA, FAMITWEPJQ, DOXEAUZJKF) What i want to achieve with this is that match string in any order(我要实现的是以任何顺序匹配字符串) For example,(例如,) with regA(EWZFKXRIVM) , it matches EWZFKXRIVM, KVEWZRXIMA both(与regA(EWZFKXRIVM) ,它匹配EWZFKXRIVM, KVEWZRXIMA) with regB(KVEWZRXIMA) , it matches only KVEWZRXIMA .(与regB(KVEWZRXIMA)匹配,仅匹配KVEWZRXIMA 。) but i expected both EWZFKXRIVM, KVEWZRXIMA(但我期望EWZFKXRIVM, KVEWZRXIMA) So my question is(所以我的问题是) Why?(为什么?) How to correct RegExp(regA, regB) for satisfiying both condition?(如何更正RegExp(regA,regB)以满足两个条件?) The only restriction is that the condition of alpahbet can't modified(唯一的限制是无法改变羊驼的病情) Edit(编辑) There is array list like this(有这样的数组列表) list = [NDRPYXVBMT,PJZEXWHSMN,FUGLCTQSOP,ADQSFENPYG, KPDFGQUIVH,DEISNLCKHG,DIRKJVQHMZ,YARDFTNPWO,RAGZFMJKIY, PEKWHSFZGR,UJOTIBRYEH,MAZNSJHXTP,CBNETZXHIY,TIYRJSONWG, FUCAMVLNDI,KXRMGDPOHU,GPMKEUFLQJ,YHBURQPOFM,VKURNBXTIH, IGLOTVNPEY,SLCGRJOPYB,HUDGIFNTPM,EPHLCQZFOR,TYDIAVUQZW, KTYBZPXSHG,CWXMLTFDJI,ERCJSWPFYH,TQSHIKRCMJ,JHBOYCFWAK, NPVAMTLXBQ,BIWAUNPSOT,TQZARXMSLH,JLYDFHWMTN,XODHNVFCWM, EWZFKXRIVM,KVEWZRXIMA ] I'll loop this like(我会像这样循环) for ( let i = 0; i < list.length; i ++){ // i will make RegExp using each String const regex = new RegExp('\b[' + list[i] + ']{' + increase + '}\w+', 'g'); const matchedList = list.toString().match(regex) } the variable of increase is for Matching count in order to get maximum for each items(increase的变量用于匹配计数,以便获得每个项目的最大值) TQZARXMSLH, JLYDFHWMTN etc..(TQZARXMSLH, JLYDFHWMTN等。)   ask by RayKim translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The regex \b[KVEWZRXIMA]{9}\w+ means: Match 9 characters of the set KVEWZRXIMA next to each other, just after a word boundary and just before there is at least one other word-character.(正则表达式\b[KVEWZRXIMA]{9}\w+意思是:在单词边界之后且KVEWZRXIMA至少一个其他单词字符之前,将匹配的KVEWZRXIMA 9个字符彼此相邻。)

The order of the characters in the set is irrelevant.(集合中字符的顺序无关紧要。) It's an unordered set of characters.(这是一组无序的字符。) The string would match eg KKKKKKKKKh because there are 9 characters next to each other and all of those 9 characters are in the predefined set ( K is within [KVEWZRXIMA] ).(该字符串将匹配例如KKKKKKKKKh因为彼此KKKKKKKKKh有9个字符,并且所有这9个字符都在预定义集中( K[KVEWZRXIMA] )。) So, if you want to match all alphabet characters, you can just use [AZ]{9} , then it has to be a character in the set of [AZ] 9 times.(因此,如果要匹配所有字母字符,则只能使用[AZ]{9} ,它必须是[AZ]集中的字符9次。) If you want to rely on the order of the characters, you cannot use an unordered set of characters, but you need to actually use the characters within the regex (outside of [] ).(如果要依赖字符的顺序,则不能使用无序的字符集,但实际上需要使用正则表达式( []之外)中的字符。) Please comment, if you have further questions.(如果您还有其他问题,请发表评论。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...