简体   繁体   English

如何为用例构造正则表达式?

[英]How to construct Regex for the usecase?

I am looking for a regular expression for the following requirement. 我正在寻找以下要求的正则表达式。 Can somebody help with this? 有人可以帮忙吗?

  1. Only decimals, -/+ and . 仅小数,-/ +和。 (dot) are Allowed. (点)被允许。
  2. Max length is 9 (including .(dot) and -/+ (minus)). 最大长度为9(包括。(点)和-/ +(减号))。

Examples: 例子:

123456789
-12345678
.12345678
-.1234567
-.123
123.45
-123.450
+23.34
_34.

Try this: ^[\\d+-.]{1,9}$ 试试这个: ^[\\d+-.]{1,9}$

[\\d+-.] - digits, +, - and . [\\d+-.] -数字,+,-和。 (dot). (点)。
{1,9} - max length is 9, min is 1 (but you can change it). {1,9} -最大长度为9,最小为1(但您可以更改)。

Here you can find how it works. 在这里,您可以找到它的工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM