89231

Html5 input pattern

Question:

I have this pattern .*?[a-z]([a-z])([a-z])([a-z]).*?(\s+)(\d+) from some online generator but it's not working.

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].

Thanks.

Answer1:

Try this one:

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

It either matches:

<ol><li>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).</li> <li>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.</li> </ol>

<a href="https://regex101.com/r/tG5nV8/3" rel="nofollow">Regex101</a>

Answer2:

The following expression should do what you describe:

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

Some notes:

<ol><li>

The {3,} construct allows you to specify repetitions within a given range. In general, it's {min,max}, but you can leave out either min or (as here) max to have an open-ended range. You can also specify an exact number of repeats by specifying a single number, e.g. {99}.

</li> <li>

The expression is essentially two complete expressions switched with alternation. Regular expressions don't allow you to say "exactly these things, in any order".

</li> <li>

I've used [a-z] to match the characters in the non-numeric part, as this is what you did in your original example.

</li> </ol>

Recommend

  • Import another Texture at runtime within THREE.JS and GLTF
  • regex: Why this negative lookahead doesn't work?
  • Regex for replacing a specific tag inside any html tag
  • Postgresql regexp_replace
  • Input buffer flush
  • Strings appear exact, but they do not match?
  • Rails db:seed error “undefined method `finder_needs_type_condition?' for nil:NilClass”
  • Extracting individual digits from a float
  • how to check the textarea content is blank using javascript?
  • How to determine the CCSID used in CPYFRMIMPF command?
  • How to solve “undefined reference to function” error?
  • Certain Arabic text gets incorrectly shown while other Arabic text gets showed normally?
  • custom string delimiters stringtemplate-4
  • Negating Regex PO BOX
  • Python cosine function precision [duplicate]
  • Validate jQuery plugin, field not required
  • jQuery: How to AJAXify WordPress Search?
  • Calculate time difference in hh:mm:ss with simple javascript/jquery
  • DIV instruction jumping to random location?
  • How to make JSON.NET deserialize to Microsoft Date Time?
  • std::remove_copy_if_ valgrind bytes in block are possibly lost in loss record
  • Mysql - How to search for 26 records that each begins with the letter of the alphabet?
  • Declaring variable dynamically in VB.net
  • How to have background script and something similar to a default popup?
  • Breeze - Deleted Items nav properties bug
  • Checking free space on FTP server
  • Regex thinks I'm nesting, but I'm not
  • javaw.exe and eclipse startup problems
  • Join two tables and save into third-sql
  • When should I choose bucket sort over other sorting algorithms?
  • Jquery - Jquery Wysiwyg return html as a string
  • R: gsub and capture
  • SVN: Merging two branches together
  • AT Commands to Send SMS not working in Windows 8.1
  • Transpose CSV data with awk (pivot transformation)
  • Buffer size for converting unsigned long to string
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • need help with bizarre java.net.HttpURLConnection behavior
  • Append folder name and increment by 1 using batch script
  • Django query for large number of relationships