热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在一个积极的工作背后,原子集团是如何运作的?-Howdoesatomicgroupinsideapositivelookbehindwork?

Idontunderstandwhytheregex(?<i:(?>\D*))\ddoesnotmatchthestringi:>1.我不明白为什么re

I don't understand why the regex (?<=i:(?>\D*))\d does not match the string i:>1.

我不明白为什么regex (?<= I:(?>\D*) \D与字符串I:>1不匹配。

The way I undertand it:

我理解的方式是:

  • at index 0: the lookbehind i won't match
  • 在索引0处:后视镜我不匹配
  • at index 1: the lookbehind i: won't match
  • 在索引1:lookbehind i:不会匹配
  • at index 2: the lookbehind i:(?>\D*) will match i: but the \d after the lookbehind won't match >
  • 索引2:lookbehind i:(?>\D*)将匹配i:但lookbehind后面的\D不会匹配>
  • at index 3: the lookbehind i:(?>\D*) will match i:> and the \d after the lookbehind will match 1 -> the regex is satisfied
  • 在索引3:后面的i:(?>\D*)将匹配i:>和\D后面的后面将匹配1 ->,regex满足。

1 个解决方案

#1


2  

See Regular Expressions Cookbook: Detailed Solutions in Eight Programming Languages:

参见正则表达式食谱:八种编程语言的详细解决方案:

.NET allows you to use anything inside lookbehind, and it will actually apply the regular expression from right to left. Both the regular expression inside the lookbehind and the subject text are scanned from right to left.

. net允许您在lookbehind内部使用任何东西,它实际上会从右到左应用正则表达式。从右到左扫描lookbehind内部的正则表达式和主题文本。

The (?<=i:(?>\D*))\d pattern does not match the 1 in i:>1 because the atomic group (?>\D*) prevents any backtracking into its pattern. The i: (actually, : and then i gets matched) is matched with \D*, and then there no way to re-match i: as the atomic group does not allow backtracking.

(?<=i:(?>\D*) \D模式与i:>1中的1不匹配,因为原子组(?>\D*)防止任何回溯到它的模式。i:(实际上,:,然后我被匹配)与\D*匹配,然后就没有办法重新匹配i:因为原子组不允许回溯。

You can also see that (?<=i:(?>[^:\d]*))\d will match 1 in i:>1 because here, [^:\d]* matches any char but : and digits, and thus only comes up to i: and i: is still there to be matched.

您还可以看到,(? <=我:(? > ^:\[d]*))\ d将匹配1我:> 1因为这里,^:\[d]*匹配任何字符,但:数字,因此只有我:我:仍有匹配。


推荐阅读
author-avatar
海峡整形美容医院少校
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有