reg ex for numbers greater than 999 in quotes, such as "1234" in javascript

To match numbers greater than 999 in quotes in JavaScript, you can use the following regular expression:

index.tsx
/"([1-9]\d{3,})"/g
19 chars
2 lines

This expression matches any string literal that contains a signed integer greater than 999. Here's what each part of the expression means:

  • /": Match a literal double quote character.
  • ([1-9]: Match any non-zero digit.
  • \d{3,}: Match three or more digits.
  • )"/: Match the closing double quote.

To use this regular expression in JavaScript, you can use the match() function of a string object:

index.tsx
const input = 'This string contains "1234" and "99999".';
const regex = /"([1-9]\d{3,})"/g;
const matches = input.match(regex);

console.log(matches); // Outputs: [ '"1234"', '"99999"' ]
187 chars
6 lines

This code searches the input string for matches of the regular expression regex, using the match() function. The resulting array contains all matches found in the string.

gistlibby LogSnag