简体   繁体   English

用于C ???-??-?-*的PHP Regex模式

[英]PHP Regex pattern for C???-??-?-*

I need to match a string to this pattern C???-??-?-* (example: CRPN-NN-N-036+ ) 我需要将字符串匹配到此模式C ???-??-?-*(例如: CRPN-NN-N-036 +

So far I found this regex pattern: 到目前为止,我发现了这种正则表达式模式:

/^(C-)*[a-zA-Z]{3}-[a-zA-Z]{2}-[a-zA-Z]-

But this doesn't work. 但这是行不通的。

^C[a-zA-Z]{3}-[a-zA-Z]{2}-[a-zA-Z]-.*

这是一个例子

The dot (.) matches a single character, without caring what that character is. 点(。)匹配单个字符,而不关心该字符是什么。 The only exception are line break characters. 唯一的例外是换行符。

So, we can use ^C.{3}-.{2}-.-.* to make the regex more general. 因此,我们可以使用^ C。{3}-。{2} -.-。*使正则表达式更通用。 This pattern even can match C???-??-?-* 此模式甚至可以匹配C ???-??-?-*

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

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