且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式量词中的反向引用

更新时间:2022-11-14 18:41:58

不是一步到位.正则表达式不能是自引用的.它们首先被构建,然后被使用.一旦构建了正则表达式,就无法重新构建/扩充.

Not in one step. Regular expressions cannot be self-referential. They are first built, and then used. No re-building/augmenting is possible once the regex is built.

您可以像之前一样匹配长度信息,并在第二步中使用它,同时评估匹配.

You can match the length info as you already do and use it in a second step, while evaluating the matches.

先发制人的评论:我知道可以用 "(.)\1" 来匹配同一个字符两次.不过,这不是我所说的自我参照".

Preemptive comment: I know that one can do "(.)\1" to match the same character twice. This is not what I mean with "self-referential", though.