-1

I have a javascript reg ex that accepts the Basic Latin character set

^[\u0000-~]+$

But I also need to not accept the dollar sign ($)

I was thinking

^[^$][\u0000-~]+$

Is this possible?

https://regex101.com/r/tw584q/1

lunchboxbill
  • 191
  • 3
  • 15
  • Just remove the `$` manually before checking or split your range into two. – miken32 Feb 26 '20 at 22:46
  • Should it fail, if there's a $-sign? Or match up to the $-sign? Or replace the $-sign? – Poul Bak Feb 26 '20 at 22:48
  • 2
    Are you sure you want to include \u000 through \u009f? Those are control codes, not latin characters. https://en.wikipedia.org/wiki/List_of_Unicode_characters#Control_codes – CAustin Feb 26 '20 at 22:53

1 Answers1

1

Assuming you just want to validate input, you can split the range around $ which should be \u0024

^[\u0000-\u0023\u0025-\u007e]+$

And for the record, ^[^$][\u0000-~]+$ would only ensure that the first character wasn’t a dollar sign.

miken32
  • 42,008
  • 16
  • 111
  • 154
  • What if... and I know this is in addition to my question... that instead of just the $ symbol, it was a specific string of ```$123``` I needed to exclude? – lunchboxbill Feb 26 '20 at 23:05
  • Then just check for it manually. Regex is not the answer to everything! – miken32 Feb 26 '20 at 23:08
  • @lunchboxbill See https://stackoverflow.com/questions/406230/regular-expression-to-match-a-line-that-doesnt-contain-a-word – Wiktor Stribiżew Feb 26 '20 at 23:48