匹配两个字符之间的单词

时间:2022-04-20 17:07:38

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 chars From:
  • 来自: - 字面序列字符来自:

  • \s* - zero or more whitespace
  • \ s * - 零个或多个空格

  • " - a quote
  • “ - 一句话

  • [^<"]* - 0+ chars other than < and "
  • [^ <“] * - 除 <和”之外的0 +字符< p>

  • \K - omit the matched text
  • \ K-省略匹配的文字

  • example - match the word example.
  • 示例 - 匹配单词示例。

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 chars From:
  • 来自: - 字面序列字符来自:

  • \s* - zero or more whitespace
  • \ s * - 零个或多个空格

  • " - a quote
  • “ - 一句话

  • [^<"]* - 0+ chars other than < and "
  • [^ <“] * - 除 <和”之外的0 +字符< p>

  • \K - omit the matched text
  • \ K-省略匹配的文字

  • example - match the word example.
  • 示例 - 匹配单词示例。

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

以下匹配@和之前的任何内容。用引号括起来

".*@(.*?)\..*"