简体   繁体   English

REGEX-正则表达式模式匹配

[英]REGEX - Regular Expression pattern matching

I've got a regex pattern that I've got to match. 我有一个必须匹配的正则表达式模式。 It should match the first three characters exactly and any other integer w/ alphabet combination like this: 它应与前三个字符完全匹配,并且与其他任何带字母组合的整数完全匹配,如下所示:

ch_1q2ew34sdfsadf334f43tf4y6y, or ch_1343ggrgr or asdfasdf2234234

I've got this so far, it works but I want to make sure I'm doing this right: 到目前为止,我已经做到了,它可以正常工作,但是我想确保自己做对了:

/([c])+([h])+([_])+[\w\d\._%+-]+/

Is this right? 这是正确的吗?

Your logic is correct but small changes in the syntax: 您的逻辑是正确的,但是语法上的微小变化:

/ch_[\w\d._%+-]+/
  • No need to put single character in [ ] and + here means match one or more characters.. i dont think you want to put that.. 不需要在[ ]加上单个字符,这里的+表示匹配一个或多个字符。.我不认为您要这样做。
  • No need to escape . 无需逃脱. inside character set.. 内部字符集
  • ( ) is a capture group and content captured inside a capture group can be back referenced with \\1 , \\2 , etc.. Use if you want to capture and dont if not required.. ( )是一个捕获组,捕获组内捕获的内容可以用\\1\\2等进行反向引用。如果要捕获,请使用,如果不需要,则不要使用。

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

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