Last active
February 6, 2024 16:22
-
-
Save nklatt/1457f0835fb8c8e84aeb58837a5bdc8c to your computer and use it in GitHub Desktop.
HTML/JS regex pattern to match one of: whole number, float, fraction or whole number <space> fraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input pattern="/^(?:(\d+\/[1-9]\d*)|(\d*(?:(\s\d+\/[1-9]\d*)|\.\d+)?))$/"> | |
<!-- | |
(?: => non-capturing group, EITHER | |
(\d+\/[1-9]\d*) => any number of digits followed by a slash then any number of digits not beginning with 0 (fraction) | |
| => OR | |
(\d*(?: => zero or more digits followed by non-capturing group, EITHER | |
( | |
\s => a space | |
\d+ => any number of digits | |
\/ => a slash | |
[1-9]\d* => one or more digits not beginning with 0 | |
) => (fraction OR whole + fraction) | |
| => OR | |
\.\d+ => a decimal point followed by any number of digits (float) | |
)?) => zero or one match for that non-capturing group | |
) | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment