简体   繁体   English

HTML5输入模式

[英]Html5 input pattern

I have this pattern .*?[az]([az])([az])([az]).*?(\\s+)(\\d+) from some online generator but it's not working. 我有这种模式.*?[az]([az])([az])([az]).*?(\\s+)(\\d+)来自某个在线生成器,但不起作用。

I need pattern which allow: 我需要允许的模式:

"minimum 3 char length string, next single space, and next minimum 1 char integer" [abc 1] or the same but in different order "minimum 1 char integer, next single space, and next minimum 3 char length string" [3 gtf]. “最小3个字符长度的字符串,下一个单个空格和下一个最小1个字符整数” [abc 1]或相同但以不同的顺序“最小1个字符整数,下一个单个空格和下一个最小3个字符长度的字符串” [3 gtf ]。

Thanks. 谢谢。

Try this one: 试试这个:

\d+\s\w{3,}|\w{3,}\s\d+

It either matches: 它匹配:

  1. One or more digits ( \\d+ ), followed by a single whitespace ( \\s ), followed by three or more word characters ( \\w{3,} ) (this is [a-zA-Z0-9], you can replace this part with [a-zA-Z] if you'd like). 一个或多个数字( \\d+ ),后跟一个空格( \\s ),后跟三个或多个单词字符( \\w{3,} )(这是[a-zA-Z0-9],您可以替换如果需要,请使用[a-zA-Z]将此部分)。
  2. Three or more word characters (this is [a-zA-Z0-9], you can replace this part with [a-zA-Z] if you'd like), followed by a single whitespace, followed by one or more digits. 三个或更多单词字符(这是[a-zA-Z0-9],如果需要,您可以用[a-zA-Z]代替此部分),后跟一个空格,后跟一个或多个数字。

Regex101 正则表达式101

The following expression should do what you describe: 下面的表达式应该执行您描述的操作:

[a-z]{3,}\s\d+|\d+\s[a-z]{3,}

Some notes: 一些注意事项:

  1. The {3,} construct allows you to specify repetitions within a given range. {3,}构造允许您指定给定范围内的重复。 In general, it's {min,max} , but you can leave out either min or (as here) max to have an open-ended range. 通常,它是{min,max} ,但是您可以省略min或(如此处所示)max来获得开放范围。 You can also specify an exact number of repeats by specifying a single number, eg {99} . 您也可以通过指定单个数字(例如{99}来指定确切的重复次数。

  2. The expression is essentially two complete expressions switched with alternation. 该表达式本质上是两个交替交替的完整表达式。 Regular expressions don't allow you to say "exactly these things, in any order". 正则表达式不允许您“以任何顺序确切地讲这些东西”。

  3. I've used [az] to match the characters in the non-numeric part, as this is what you did in your original example. 我使用[az]来匹配非数字部分中的字符,因为这是您在原始示例中所做的。

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

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