关于正则表达式分组构造 [英] About a Regular Expression Grouping Construct

查看:100
本文介绍了关于正则表达式分组构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

你知道如何使用这个分组构造吗?


(?>)


我在MSDN上找到了它的参考,但仍然无法完全理解它。

以下是它的描述:


Nonbacktracking子表达式(也称为贪婪子表达式)。

子表达式完全匹配一次,然后在回溯中不会零碎地参与
。 (也就是说,子表达式只匹配仅由子表达式匹配的字符串。)


有谁可以告诉我如何使用它?如果有人知道,请给我一个例子:)

非常感谢!


祝你好运,

Laser Lu。<视觉工作室中的

解决方案

你可以尝试使用RegularExpressionValidator并在那里你可以使用你的ExpString!

" Laser Lu" < LA ****** @ hotmail.com> escreveu na mensagem

news:48 ********************* @ news.microsoft.com ...

大家好,你知道如何使用这个分组结构吗?

(?>)

我在MSDN上找到了它的参考但是仍然无法完全理解它。
以下是它的描述:

非回溯子表达式(也称为贪婪子表达式)。
子表达式完全匹配一次,然后不参与零碎的回溯。 (也就是说,子表达式仅匹配仅由子表达式匹配的字符串。)

任何人都可以告诉我如何使用它吗?如果有人知道,请给我看一个
示例:)非常感谢!

最好的问候,
Laser Lu。



Hello Daniel,谢谢:)

但我想说的是,RegularExpressionValidator控件只能在ASP中使用
.NET Web Applications及其内置编辑器非常简单。监管机构

和Expresso都比它好。


然而,我的问题是分组构造''(?>)'是什么意思?我需要一个关于如何使用这个构造的示例代码:)

在visual studio中你可以尝试使用RegularExpressionValidator和
Laser Lu < LA ****** @ hotmail.com> escreveu na mensagem
新闻:48 ********************* @ news.microsoft.com ......

大家好,你知道如何使用这个分组构造吗?
(?>)

我在MSDN上找到了它的参考,但仍然可以完全不理解它。以下是它的描述:

非回溯子表达式(也称为贪婪子表达式)。子表达式完全匹配一次,然后
不会零碎地参与回溯。 (也就是说,
子表达式只匹配仅由
子表达式匹配的字符串。)

任何人都可以告诉我如何使用它吗?如果有人知道,请告诉我
一个例子:)非常感谢!

最好的问候,
Laser Lu。




您可以使用分组构造来提取字符串的一部分。对于

示例,假设您要从

后面的字符串中提取颜色值(即红色):


字符串说明color =" red"


您可以使用正则表达式执行此操作:color ="(?< color> \ S *)"


以下代码使用正则表达式和Match.Groups属性

打印出值red:


Regex rgx =新的正则表达式(@" color = \""(?< color> \ S *)\""");

匹配m = rgx.Match(" a string description color = \" red\"");

if(m.Success)

{

string color = m.Groups [" color"]。值;

Console.WriteLine(颜色);

}


HTH,Jakob。


" Laser Lu"写道:

你好丹尼尔,谢谢:)
但我想说,只有ASP.NET Web应用程序中的RegularExpressionValidator控件可用
,它的内置编辑器很简单。 Regulator
和Expresso都比它好。

然而,我的问题是分组构造''(?>)'是什么意思?我只需要一个关于如何使用这个构造的示例代码:)在visual studio中你可以试试RegularExpressionValidator和
可以使用你的ExpString!

Laser Lu < LA ****** @ hotmail.com> escreveu na mensagem
新闻:48 ********************* @ news.microsoft.com ......

大家好,你知道如何使用这个分组构造吗?
(?>)

我在MSDN上找到了它的参考,但仍然可以完全不理解它。以下是它的描述:

非回溯子表达式(也称为贪婪子表达式)。子表达式完全匹配一次,然后
不会零碎地参与回溯。 (也就是说,
子表达式只匹配仅由
子表达式匹配的字符串。)

任何人都可以告诉我如何使用它吗?如果有人知道,请告诉我
一个例子:)非常感谢!

最好的问候,
Laser Lu。




Hello, everybody,
do you know how to use this Grouping Construct?

(?> )

I''ve found its reference on MSDN, but still can not understand it totally.
The following is its description:

Nonbacktracking subexpression (also known as a "greedy" subexpression). The
subexpression is fully matched once, and then does not participate piecemeal
in backtracking. (That is, the subexpression matches only strings that would
be matched by the subexpression alone.)

Can anybody tell me how to use it? If someone knows, please show me an example:)
Thanks a lot!

Best regards,
Laser Lu.

解决方案

in the visual studio u can try the RegularExpressionValidator and there you
can use your ExpString!

"Laser Lu" <la******@hotmail.com> escreveu na mensagem
news:48*********************@news.microsoft.com...

Hello, everybody,
do you know how to use this Grouping Construct?

(?> )

I''ve found its reference on MSDN, but still can not understand it totally.
The following is its description:

Nonbacktracking subexpression (also known as a "greedy" subexpression).
The subexpression is fully matched once, and then does not participate
piecemeal in backtracking. (That is, the subexpression matches only
strings that would be matched by the subexpression alone.)

Can anybody tell me how to use it? If someone knows, please show me an
example:) Thanks a lot!

Best regards,
Laser Lu.



Hello Daniel, thank you:)
But I''d like to say that the RegularExpressionValidator control is only available
in ASP.NET Web Applications, and its built-in editor is simple. Both Regulator
and Expresso are better than it.

However, my question is what does the Grouping Construct ''(?> )'' mean? I
just need a sample code on how to use this construct:)

in the visual studio u can try the RegularExpressionValidator and
there you can use your ExpString!

"Laser Lu" <la******@hotmail.com> escreveu na mensagem
news:48*********************@news.microsoft.com...

Hello, everybody,
do you know how to use this Grouping Construct?
(?> )

I''ve found its reference on MSDN, but still can not understand it
totally. The following is its description:

Nonbacktracking subexpression (also known as a "greedy"
subexpression). The subexpression is fully matched once, and then
does not participate piecemeal in backtracking. (That is, the
subexpression matches only strings that would be matched by the
subexpression alone.)

Can anybody tell me how to use it? If someone knows, please show me
an example:) Thanks a lot!

Best regards,
Laser Lu.




You can use the grouping construct for extracting parts of a string. For
example, say you want to extract the value of color (i.e. "red") from the
following string:

string description color="red"

You can do this using the regular expression: color="(?<color>\S*)"

The following code uses the regular expression and the Match.Groups property
to print out the value "red":

Regex rgx = new Regex(@"color=\""(?<color>\S*)\""");
Match m = rgx.Match("a string description color=\"red\"");
if (m.Success)
{
string color = m.Groups["color"].Value;
Console.WriteLine(color);
}

HTH, Jakob.

"Laser Lu" wrote:

Hello Daniel, thank you:)
But I''d like to say that the RegularExpressionValidator control is only available
in ASP.NET Web Applications, and its built-in editor is simple. Both Regulator
and Expresso are better than it.

However, my question is what does the Grouping Construct ''(?> )'' mean? I
just need a sample code on how to use this construct:)

in the visual studio u can try the RegularExpressionValidator and
there you can use your ExpString!

"Laser Lu" <la******@hotmail.com> escreveu na mensagem
news:48*********************@news.microsoft.com...

Hello, everybody,
do you know how to use this Grouping Construct?
(?> )

I''ve found its reference on MSDN, but still can not understand it
totally. The following is its description:

Nonbacktracking subexpression (also known as a "greedy"
subexpression). The subexpression is fully matched once, and then
does not participate piecemeal in backtracking. (That is, the
subexpression matches only strings that would be matched by the
subexpression alone.)

Can anybody tell me how to use it? If someone knows, please show me
an example:) Thanks a lot!

Best regards,
Laser Lu.




这篇关于关于正则表达式分组构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆