mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
Simplify some regular expressions
There's a fair number of regular expressions througout the code-base which are slightly more verbose than strictly necessary, in particular: - We have a lot of regular expressions that use `[0-9]` explicitly, and those can be simplified to use `\d` instead. - We have one instance of a regular expression containing a `A-Za-z0-9_` sequence, which can be simplified to use `\w` instead.
This commit is contained in:
parent
0a366dda6a
commit
c42887221a
8 changed files with 35 additions and 38 deletions
|
@ -90,7 +90,7 @@ class AForm {
|
|||
str = `0${str}`;
|
||||
}
|
||||
|
||||
const numbers = str.match(/([0-9]+)/g);
|
||||
const numbers = str.match(/(\d+)/g);
|
||||
if (numbers.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
@ -202,13 +202,13 @@ class AForm {
|
|||
if (sepStyle > 1) {
|
||||
// comma sep
|
||||
pattern = event.willCommit
|
||||
? /^[+-]?([0-9]+(,[0-9]*)?|,[0-9]+)$/
|
||||
: /^[+-]?[0-9]*,?[0-9]*$/;
|
||||
? /^[+-]?(\d+(,\d*)?|,\d+)$/
|
||||
: /^[+-]?\d*,?\d*$/;
|
||||
} else {
|
||||
// dot sep
|
||||
pattern = event.willCommit
|
||||
? /^[+-]?([0-9]+(\.[0-9]*)?|\.[0-9]+)$/
|
||||
: /^[+-]?[0-9]*\.?[0-9]*$/;
|
||||
? /^[+-]?(\d+(\.\d*)?|\.\d+)$/
|
||||
: /^[+-]?\d*\.?\d*$/;
|
||||
}
|
||||
|
||||
if (!pattern.test(value)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue