本文介绍了“可选"量词 ('??') 的惰性版本在正则表达式中有用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不出我想在正则表达式中使用 ?? 的情况,但也许我想得不够仔细.

I cannot think of a situation where I'd want to use ?? in a regular expression, but maybe I'm not thinking hard enough.

推荐答案

可能是一个分隔符分隔的列表,而您不想匹配任何终止分隔符.

Maybe a delimiter-separated list, and you don't want to match any terminating delimiter.

^((?:[^,]+,??)+),?$

这将从 "a,b,c," 中捕获 "a,b,c",其中非惰性变体将在捕获组.

That would capture "a,b,c" from "a,b,c,", where as the non-lazy variant would include the comma in the capture-group.

这篇关于“可选"量词 ('??') 的惰性版本在正则表达式中有用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 00:40