[英]How do i write a regex pattern for a string ending with 3 numbers or a hypen?
I have a string that can either end with a hiphen or a 3 digit number (or a completely random text.) 我有一个字符串,可以以hihen或3位数字(或完全随机的文本)结尾。
I will need to evaluate a condition if it ends with a hiphen or a 3 digit number.(if its not a number or a hyphen,i am good) 我需要评估一个条件,条件是它是否以hiphen或3位数字结尾。(如果不是数字或连字符,则表示我很好)
I tried to use 我尝试使用
myString.matches("^.*\\d")
I can try to tweek this,with some help 我可以尝试一些帮助
but i really dont know how i can specify 3 digits along with "-". 但是我真的不知道如何指定3位数字和“-”。 I can probably use
myString.endsWith("-")
for the latter,but if i can do it with regex,it'd be great too. 我可以为后者使用
myString.endsWith("-")
,但是如果我可以用正则表达式来做,那也很好。
Some samples: 一些样本:
Try: 尝试:
^.*(\\d{3}|-)$ ^。*(\\ d {3} |-)$
The $ means "finished/ends with" $表示“完成/结尾为”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.