![](/img/trans.png)
[英]How can I use a Regular Expression to return a number of numbers at the end of a string of digits
[英]Regular Expressions (.NET) - How can I match a pattern that contains a variable number of digits at the end of the string?
string src = "portfolio1, portfolio2, portfolio20, portfolio300";
我想匹配所有格式為@“ portfolio \\ d”的字符串,其中\\ d的長度可以是1-3位數。 我已經讀過使用{a,b}應該可以,所以我嘗試:
pattern = @"portfolio\d{1, 3}"
在字符串src中搜索此模式將返回一個空集。 以下模式部分起作用:
pattern = @"portfolio\d"
pattern = @"portfolio\d{1}"
嘗試這個:
pattern = @"portfolio\d{1,3}"
請注意,不要像示例中那樣在方括號之間放置空格。 這就是為什么它不能正常工作的原因。
在Expresso中運行模式“ portfolio \\ d {1,3}”,我在每個投資組合上獲得4個匹配項。 空間是關鍵。
String pattern = @"^(?:(?:portfolio\d{1,3})(?:\x2C\s)*)+$";
我的嘗試。 將匹配任意數量的逗號分隔的portfolio\\d{1,3}
的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.