mrspoopybutthole
mrspoopybutthole

Reputation: 117

Need help figuring out how to write this Regex properly

I am trying to make a regex test that returns true for the following conditions:

The order does not matter except that string[0] should be '#'.

So far I have: /^#[A-F0-9^!G-Z]/i but for some reason, it returns strings that have letters after F (like G or J) as true.

Upvotes: 1

Views: 52

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626802

You can use

^#[0-9A-Fa-f]*$

Details:

  • ^ - start of string
  • # - a hash symbol
  • [0-9A-Fa-f]* - zero or more hex chars (note it can be written as [[:xdigit:]]* in some regex flavors, but not in ECMAScript flavor used in JavaScript)
  • $ - end of string.

Upvotes: 1

Related Questions