[英]Regular Expressions (.NET) - How can I match a pattern that contains a variable number of digits at the end of the string?
[英]How can I use a Regular Expression to return a number of numbers at the end of a string of digits
我有一串数字可以改变长度,我想只返回最后4位数字。 我会用积极的回顾吗? 并使用$来锚定?
使用这个正则表达式\\d{4}$
如果您的字符串可以是任意长度,并且您希望匹配具有0到3个字符的情况,则应使用:
\d?\d?\d?\d?$
或者,如果正则表达式引擎理解它:
\d{0-4}$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.