regex expression get number 60 without 1 in javascript

Here is a regex expression in javascript to get 60 without 1:

index.tsx
/^[^1]*60[^1]*$/
17 chars
2 lines

This expression will match any string that contains the number 60, but does not contain the number 1.

  • The ^ character matches the start of the string.
  • The [^1] character class matches any character that is not the digit 1.
  • The * operator quantifies the preceding character class, matching zero or more characters that are not 1.
  • The 60 matches the literal sequence of 6 and 0.
  • The [^1]* at the end matches zero or more characters that are not 1 until the end of the string ($ sign).

So this expression will match strings such as "60", "5060", "0660", "60ab", but not "16", "601", "610", "161", etc.

gistlibby LogSnag