C# 中的 Quantifiers函数

首页 / C#入门教程 / C# 中的 Quantifiers函数

量词指定输入字符串中必须存在前一个元素(可以是字符、组或字符类)的实例数,才能发生匹配。

Quantifier Description Pattern Matches
* Matches the previous element zero or more times. \d*\.\d ".0", "19.9", "219.9"
+ Matches the previous element one or more times. "be+" "bee" in "been", "be" in "bent"
? Matches the previous element zero or one time. "rai?n" "ran", "rain"
{ n } Matches the previous element exactly n times. ",\d{3}" ",043" in "1,043.6", ",876", ",543", and ",210" in "9,876,543,210"
{ n ,} Matches the previous element at least n times. "\d{2,}" "166", "29", "1930"
{ n , m } Matches the previous element at least n times, but no more than m times. "\d{3,5}" "166", "17668" "19302" in "193024"
*? Matches the previous element zero or more times, but as few times as possible. \d*?\.\d ".0", "19.9", "219.9"
+? Matches the previous element one or more times, but as few times as possible. "be+?" "be" in "been", "be" in "bent"
?? Matches the previous element zero or one time, but as few times as possible. "rai??n" "ran", "rain"
{ n }? Matches the preceding element exactly n times. ",\d{3}?" ",043" in "1,043.6", ",876", ",543", and ",210" in "9,876,543,210"
{ n ,}? Matches the previous element at least n times, but as few times as possible. "\d{2,}?" "166", "29", "1930"
{ n , m }? Matches the previous element between n and m times, but as few times as possible. "\d{3,5}?" "166", "17668" "193", "024" in "193024"

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

如何设计一个秒杀系统 -〔许令波〕

玩转webpack -〔程柳锋〕

从0打造音视频直播系统 -〔李超〕

性能测试实战30讲 -〔高楼〕

人人都能学会的编程入门课 -〔胡光〕

编译原理实战课 -〔宫文学〕

分布式数据库30讲 -〔王磊〕

朱涛 · Kotlin编程第一课 -〔朱涛〕

现代C++20实战高手课 -〔卢誉声〕

好记忆不如烂笔头。留下您的足迹吧 :)