贪婪的表达式如何在正则表达式中起作用? [英] How the greedy expressions works in regular expressions?

查看:76
本文介绍了贪婪的表达式如何在正则表达式中起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在正则表达式中,我对以下表达式感到困惑。



In the regular expressions i'm confusing about the following expressions.

.*




*?




+?




??





上述表达式的工作原理。

任何人都可以给我一个例子。



我尝试过:



我在google上研究过,但在处理上面提到的表达式时我很困惑。



How the above expressions works.
Can anybody give me with an examples.

What I have tried:

I've researched on google, but while working with the mentioned expressions I'm confusing.

推荐答案

OK ...

。*是任何字符,任意次数(包括零)

。*?是和字符,任意次数(包括零),尽可能少

。+?是任何角色,至少一个,尽可能少

。??是任何角色,零或一个,尽可能少



。是任何角色,零或一个



获取的副本Expresso [ ^ ] - 它是免费的,它会检查并生成正则表达式。理解(和测试)它们真的很有帮助!
OK...
.* is "any character, any number of times (including zero)"
.*? is "and character, any number of times (including zero), as few as possible"
.+? is "any character, at least one of, as few as possible"
.?? is "any character, zero or one of, as few as possible"
And
.? is "any character, zero or one of"

Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions. It really helps to understand (and test) them!


作为OriginalGriff的答案的补充,你可以尝试这个网站:

Regular-Expressions.info - Regex教程,示例和参考 - Regexp模式 [ ^ ]

在这里你可以阅读贪婪的量词:正则表达式参考:量词 [ ^ ]

几乎可以解释所有正则表达式。



我通常使用的工具是RegExTest.exe。开始使用非常简单,但与.NET一起很好。

它也是免费的,可以在这里下载: RegExTest下载| SourceForge.net [ ^ ]
As an addition to OriginalGriff's answer, you can try this website:
Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns[^]
Here you can read greedy quantifiers: Regular Expressions Reference: Quantifiers[^]
It pretty much explains all about regular expressions.

The tool I usually us is the RegExTest.exe. It is very simple to get started with, but good together with .NET.
It is also free and can be downloaded here: RegExTest download | SourceForge.net[^]


除了以前的解决方案,这里有一个工具可以帮助理解RegEx

Debuggex:Online视觉正则表达式测试仪。 JavaScript,Python和PCRE。 [ ^ ]

和最常见方言之一的文件

perlre - perldoc.perl.org [ ^ ]
In addition to previous solutions, here is a tool that can help to understand a RegEx
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
and documentation to one of the most common dialects
perlre - perldoc.perl.org[^]


这篇关于贪婪的表达式如何在正则表达式中起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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