我正在寻找像这样的字符串中的@
字符:
@test@example
hello@there
myemail@gmail.com
我只想匹配
@
,如果它不在行的开头或结尾,即在此示例中不匹配第一个@
。我该怎么做呢?
最佳答案
如果您使用的语言支持lookahead
和lookbehind
,则可以使用
(?<=.)@(?=.)
正则表达式细目
(?<=.) #Assure that there is at least one character present before @
@ #Match @
(?=.) #Assure that there is at least one character present after @
或者
(?<!^)@(?!$)
正则表达式细目
(?<!^) #Assure that @ do not follows starting of string
@ #Match @
(?!$) #Assure that @ is not followed by end of string
关于regex - 如何在字/行中间找到一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37509015/