正则表达式在notepad ++中不匹配

时间:2023-01-17 23:37:05

I am trying to match this regular expression in notepad++, but I am getting an error saying that it is invalid.

我试图在记事本++中匹配这个正则表达式,但我收到一个错误,说它无效。

My Regex:

{{#lsth:JointEntero_May_2015\|2015_May_([0-9]+)}}

What I am trying to match:

我想要匹配的内容:

{{#lsth:JointEntero_May_2015|2015_May_8}}

Why is it failing?

它为什么失败?

1 个解决方案

#1


The regex that works is

有效的正则表达式是

\{\{\#lsth\:JointEntero_May_2015\|2015_May_([0-9]+)\}\}

It is working because the { and } characters must be escaped in order to get matched as literal symbols. {} are usually used as quantifiers where we can set min and/or max characters corresponding to the preceding pattern to match. See the documentation:

这是有效的,因为{和}字符必须被转义才能匹配为文字符号。 {}通常用作量词,我们可以设置与前一个模式相对应的最小和/或最大字符以匹配。查看文档:

{n}
Matches n copies of the element it applies to.
{n,}
Matches n or more copies of the element it applies to.
{m,n}
Matches m to n copies of the element it applies to, as much it can.
{n,}?,{m,n}?
Like the above, but match as few copies as they can. Compare with *? and friends.

{n}匹配它适用的元素的n个副本。 {n,}匹配它适用的元素的n个或多个副本。 {m,n}尽可能匹配m到它应用的元素的n个副本。 {N,}?,{M,N}?像上面一样,但尽可能少地匹配副本。与之比较 *?和朋友。

#1


The regex that works is

有效的正则表达式是

\{\{\#lsth\:JointEntero_May_2015\|2015_May_([0-9]+)\}\}

It is working because the { and } characters must be escaped in order to get matched as literal symbols. {} are usually used as quantifiers where we can set min and/or max characters corresponding to the preceding pattern to match. See the documentation:

这是有效的,因为{和}字符必须被转义才能匹配为文字符号。 {}通常用作量词,我们可以设置与前一个模式相对应的最小和/或最大字符以匹配。查看文档:

{n}
Matches n copies of the element it applies to.
{n,}
Matches n or more copies of the element it applies to.
{m,n}
Matches m to n copies of the element it applies to, as much it can.
{n,}?,{m,n}?
Like the above, but match as few copies as they can. Compare with *? and friends.

{n}匹配它适用的元素的n个副本。 {n,}匹配它适用的元素的n个或多个副本。 {m,n}尽可能匹配m到它应用的元素的n个副本。 {N,}?,{M,N}?像上面一样,但尽可能少地匹配副本。与之比较 *?和朋友。