[英]Regex with digits and some special characters
I need help with creating a regex that would recognize tokens in text. 我需要有关创建可识别文本中标记的正则表达式的帮助。
Token requirements are as follows: 令牌要求如下:
$
$
开头和结尾 _
_
任意组合 .
.
, meaning: $some.valid.sample$
is valid $some.valid.sample$
有效 $some..invalid.sample$
is not $some..invalid.sample$
不是 $some.valid[0].sampl$
is valid $some.valid[0].sampl$
有效 $some.invalid[].sample$
is not $some.invalid[].sample$
不是 additional requirements (after discussion in comments): 附加要求(在评论中讨论之后):
.
.
if they are not at the end (ie if they are not just before closing $
) $
之前) $
$
之间的内容 Can anyone help me out with this? 谁能帮我这个忙吗?
So far I have \\$([A-Za-z0-9._]*(\\[\\d+\\])*)+]$
到目前为止,我有
\\$([A-Za-z0-9._]*(\\[\\d+\\])*)+]$
根据注释中更新的规则,这是您需要的:
\$(?=[^\$]{1,64}\$)\w+(?:\[\d+\])?(?:\.\w+(?:\[\d+\])?)*\$
How about this pattern: 这个模式怎么样:
\$\w+?.?\w*?(\[\d+\]?)?.?\w*?\$
You can test it here 你可以在这里测试
it is a little too narrow though. 虽然有点太狭窄了。 I would take the suggestion by @Wiktor Stribizew
我会接受@Wiktor Stribizew的建议
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.