[英]RegEx - avoid matching a word ending with a specific character
I am trying to create a regex (regexp) that will avoid matching words ending with '@', '-', ',': ':' and '>'我正在尝试创建一个正则表达式 (regexp),它将避免匹配以 '@'、'-'、',': ':' 和 '>' 结尾的单词
The rules are as follows - the name should begin with @ can have any character after it except the ones above.规则如下 - 名称应以 @ 开头,后面可以有除上述字符之外的任何字符。 So in the following strings: 'zhsvfghzfajhuib@Bobbie?skvshvfhj?G,' - @Bobbie, will match '768huehfvwkjv@Lana97958749ndgjhb.G!'
所以在以下字符串中:'zhsvfghzfajhuib@Bobbie?skvshvfhj?G,' - @Bobbie,将匹配'768huehfvwkjv@Lana97958749ndgjhb.G!' - @Lana9 will match ',vbfnhytjnh@Sammie-sjvjhsvfjj!G!kjdbdjb' - @Sammie- will NOT match, because the character after the name is in the above range.
- @Lana9 将匹配 ',vbfnhytjnh@Sammie-sjvjhsvfjj!G!kjdbdjb' - @Sammie- 将不匹配,因为名称后面的字符在上述范围内。
My latest attempt is: @(?[A-Za-z]+)[^@-:.>] but all it did was to remove the last character and still matched.我最近的尝试是:@(?[A-Za-z]+)[^@-:.>] 但它所做的只是删除最后一个字符并且仍然匹配。
I tried:我试过了:
If supported, you can use an atomic group :如果支持,您可以使用原子组:
@(?>(?<name>[A-Za-z]+))[^@\-!:>]
Another option is using a positive lookahead with a capture group and a backreference as there is no backtracking in lookarounds :另一种选择是使用带有捕获组和反向引用的正向前瞻,因为环视中没有回溯:
@(?=([A-Za-z]+))\1[^@\-!:>]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.