正则识别特定模式
我正在编写正则是我的字符串中的特定模式。我必须确定字符串是否满足我想要的所有模式。我有以下标准:
- 该名称应以“ p”或“ q”或“ r”开始
- ,之后的第一个字符应匹配字符串,
- 如果存在xyz,则应 匹配“ xyz”或“ abcd” “ H”或“ D”,如果存在“ ABCD”,则第9个字符应为“ H”或“ D”。
字符串可能是:
PXYZ****H***** -> Should be true
QABCD****H***** -> Should be true
AXYG****Z***** -> Should be false
RABCD****H=D***** -> Should be true
如果字符串以开头([P | Q | r])\ W+
,我已经尝试过,不确定如何结合其他。
I am writing regex to find a specific pattern in my string. I have to identify if the string satisfy all the pattern that I am looking for. I have following criteria:
- The name should start with either "P" or "Q" or "R"
- Following the first character the string should match either "XYZ" or "ABCD"
- If the XYZ is present then the 8th character should either be "H" or "D", if "ABCD" is present the 9th character should be either "H" or "D".
String could be:
PXYZ****H***** -> Should be true
QABCD****H***** -> Should be true
AXYG****Z***** -> Should be false
RABCD****H=D***** -> Should be true
I have tried if the string starts with ([P|Q|R])\w+
, not sure how to combine others.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
请参阅正则表达式证明。
说明
Use
See regex proof.
EXPLANATION
此正则具体的是:
pqr
xyz
或abcd
h
或<代码> d 结束前的五个字符是我的尝试:
它对您有用吗?
What is specific about this regex is that:
PQR
XYZ
orABCD
H
orD
five chars before the endHere's my attempt:
Does it work for you?