星号和加号定义问题 [英] asterisk and Plus definition issue

查看:60
本文介绍了星号和加号定义问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始阅读正则表达式,在文章中我发现了这些:

I start reading Regex, and in article i find these :

The asterisk or star tells the engine to attempt to match the preceding token zero or more times. 

The plus tells the engine to attempt to match the preceding token once or more

我在谷歌上搜索了上述句子的含义,但我真的不明白术语前置标记一次或多次前置标记零次或多次是什么意思,有人可以通过一个例子来解释这些吗?任何帮助将不胜感激.

i googled about meaning of above sentences, but i really can not understand what is meant by the term preceding token once or more and preceding token zero or more times, some one can explain these by an example? any help will be appreciated.

推荐答案

preceding token"的意思就是,前面的标记.

"preceding token" means just that, the preceding token.

*+ 的效果是句子的其余部分:

The effect the * or + has is the rest of the sentence:

  • * 表示前面的标记,无论是什么,都可以匹配零次或多次
  • + 表示前面的标记,无论是什么,都可以匹配一次或多次
  • * means that the preceding token, whatever that may be, can be matched zero or more times
  • + means that the preceding token, whatever that may be, can be matched one or more times

这里的令牌"是一个模式单元,它可以是以下示例中的任何一个以及更多示例:

A "token" here is one unit of pattern, it can be any of the following examples + many more:

  • 单个字符:A+匹配一个或多个AA*匹配零个或多个A>s,比如AAAAA
  • 字符类:\d+ 匹配一个数字,一次或多次,如123450
  • 字符集:[af]+ 匹配从 af 的任何字母,一次或多次,如 afdbe
  • 一组:(test)+匹配文本test一次或多次,如testtesttest
  • A single character: A+ matches one or more As, and A* matches zero or more As, like AAAAA
  • A character class: \d+ matches a digit, one ore more times, like 123450
  • A character set: [a-f]+ matches any letter from a to f, one or more times, like afdbe
  • A group: (test)+ matches the text test one or more times, like testtesttest

零或..."表示模式也可能不匹配,这里是一个示例模式:123450*6,这将匹配以下示例:

"zero or ..." means that the pattern may also match nothing, here is an example pattern: 123450*6, this will match the following examples:

  • 1234506 <-- 这里 0 出现一次(大于零)
  • 123450006 <-- 这里出现了 3 次(也超过零次)
  • 123456 <-- 这里出现零次,如果你使用*,这是合法的,但如果模式是123450+6,则不是.
  • 1234506 <-- here the 0 occurs once (which is more than zero)
  • 123450006 <-- here it occurs three times (also more than zero)
  • 123456 <-- here it occurs zero times, which is legal if you use the *, but not if the pattern had been 123450+6.

这篇关于星号和加号定义问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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