[英]How to creat a regex for a something like X.0.4472.114 where X is a number?
I want to create a regex for something from the template:我想为模板中的内容创建一个正则表达式:
X .
X 。 number .
数字 。 number number number number .
号码号码号码号码。 number number
号码 号码
or :要么 :
X .
X 。 number .
数字 。 number number number number .
号码号码号码号码。 number number number
号码号码号码
Where X is a variable that contains a number.其中 X 是一个包含数字的变量。
eg:例如:
X = 102 X = 102
then:然后:
102.3.2345.234 is a valid 102.3.2345.23 is valid too. 102.3.2345.234是有效的102.3.2345.23也是有效的。
I have tried to use "[" + X + "]" + "[.]0[.][\\\\d][\\\\d][\\\\d][\\\\d][.][\\\\d][\\\\d]"
, but it's not working我曾尝试使用
"[" + X + "]" + "[.]0[.][\\\\d][\\\\d][\\\\d][\\\\d][.][\\\\d][\\\\d]"
,但它不起作用
如果您在变量x
有数字开头,那么您的正则表达式模式可以构造为
String pattern = x + "\\.\\d\\.\\d{4}.\\d{2,3}";
You can use x + "\\\\.\\\\d\\\\.\\\\d{4}\\\\.\\\\d{2,3}"
as the pattern.您可以使用
x + "\\\\.\\\\d\\\\.\\\\d{4}\\\\.\\\\d{2,3}"
作为模式。
Details of the regex:正则表达式的详细信息:
\\.
: A dot \\d
: A single digit \\d
: 一位数\\d{4}
: 4 digits \\d{4}
: 4 位数字\\d{2,3}
: 2 or 3 digits \\d{2,3}
: 2 或 3 位数字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.