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..invalid.sample$
is not $some.valid[0].sampl$
is valid $some.invalid[].sample$
is not 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+\\])*)+]$
根据注释中更新的规则,这是您需要的:
\$(?=[^\$]{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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.