I need a regular expression that should give back a true/false value.
我需要一个应该返回true / false值的正则表达式。
Example:
From: "johndoe@example.com" <johndoe@example.com>
来自:“johndoe@example.com”
@example.com>
I need to match the word example only between : and <, not outside
我需要在:和 <之间匹配单词示例,而不是在外面< p>
3 个解决方案
#1
2
If you need to match a specific substring after a known pattern that you do not want to be returned in the match, you can use the PCRE \K
operator that omits all text matched so far.
如果您需要在不希望在匹配中返回的已知模式之后匹配特定子字符串,则可以使用省略到目前为止匹配的所有文本的PCRE \ K运算符。
You can use
您可以使用
^From:\s*"[^<"]*\Kexample
See the regex demo
请参阅正则表达式演示
The regex matches:
正则表达式匹配:
-
^
- start of string -
From:
- literal sequence of charsFrom:
-
\s*
- zero or more whitespace -
"
- a quote -
[^<"]*
- 0+ chars other than<
and"
-
\K
- omit the matched text -
example
- match the wordexample
.
^ - 字符串的开头
来自: - 字面序列字符来自:
\ s * - 零个或多个空格
“ - 一句话
[^ <“] * - 除 <和”之外的0 +字符< p>
\ K-省略匹配的文字
示例 - 匹配单词示例。
You can further tweak the regex by adding case insensitive flags, etc.
您可以通过添加不区分大小写的标志等来进一步调整正则表达式。
#2
0
try this, you can test here: https://regex101.com/r/yQ1zQ7/2
试试这个,你可以在这里测试:https://regex101.com/r/yQ1zQ7/2
\b\@(.*)?\.(.*)?"
(I've update to use with other domain name)
(我已更新与其他域名一起使用)
#3
0
The below matches anything after @ and before . enclosed in quotes
以下匹配@和之前的任何内容。用引号括起来
".*@(.*?)\..*"
#1
2
If you need to match a specific substring after a known pattern that you do not want to be returned in the match, you can use the PCRE \K
operator that omits all text matched so far.
如果您需要在不希望在匹配中返回的已知模式之后匹配特定子字符串,则可以使用省略到目前为止匹配的所有文本的PCRE \ K运算符。
You can use
您可以使用
^From:\s*"[^<"]*\Kexample
See the regex demo
请参阅正则表达式演示
The regex matches:
正则表达式匹配:
-
^
- start of string -
From:
- literal sequence of charsFrom:
-
\s*
- zero or more whitespace -
"
- a quote -
[^<"]*
- 0+ chars other than<
and"
-
\K
- omit the matched text -
example
- match the wordexample
.
^ - 字符串的开头
来自: - 字面序列字符来自:
\ s * - 零个或多个空格
“ - 一句话
[^ <“] * - 除 <和”之外的0 +字符< p>
\ K-省略匹配的文字
示例 - 匹配单词示例。
You can further tweak the regex by adding case insensitive flags, etc.
您可以通过添加不区分大小写的标志等来进一步调整正则表达式。
#2
0
try this, you can test here: https://regex101.com/r/yQ1zQ7/2
试试这个,你可以在这里测试:https://regex101.com/r/yQ1zQ7/2
\b\@(.*)?\.(.*)?"
(I've update to use with other domain name)
(我已更新与其他域名一起使用)
#3
0
The below matches anything after @ and before . enclosed in quotes
以下匹配@和之前的任何内容。用引号括起来
".*@(.*?)\..*"