-3

I am using [0-9A-F]{3,6} but it if a 4 number digit triggers it fails. Does this regex check for the amount of characters from 3 - 6? If there is something I can use to check from 1-9 that would be great. Am I missing something obvious here?

pcproff
  • 582
  • 1
  • 6
  • 25
  • 1
    What pattern are you trying to match? The above regex seems to catch 3 to 6 length characters that are hexadecimal ie, `0-9` or `A-F`. – Anthony Forloney Mar 15 '15 at 01:10
  • Thanks for the response. The log file can either can back with either 1-9 characters. (numerical) It has to know how to handle either 1 or 123456789 – pcproff Mar 15 '15 at 01:14
  • Only numerics of one or more length? (ie, `[1-9]+`?) – Anthony Forloney Mar 15 '15 at 01:15
  • 3
    Your question is self contradictory. The pattern seems to be for hexadecimal, but the next sentence seems to be asking about decimal. The question title seems to ask about "up to 3" digit number, but the regex seems to require 3 to 6 digits. And now your comment has a 9 digit number! Please be *clear* about what you are really trying to check. – Stephen C Mar 15 '15 at 01:16
  • 1
    *"Am I missing something obvious here?"* - possibly what you are missing is some understanding of what your regex actually says. – Stephen C Mar 15 '15 at 01:18
  • Anthony the value can be either 1 or 6 or 9 characters in length ie. 0 or 123456 or 123456789 whatever the log throws at me. – pcproff Mar 15 '15 at 01:26
  • 1
    @pcproff use regex101.com and type in your regex. On the right sidebar you should see an explanation of your regex. Basically, yes `{3,6}` will repeat the precedent token from 3 to 6 times. Now use your logic to change this from 1 to 9. – HamZa Mar 15 '15 at 01:39
  • 1
    @pcproff Please consider bookmarking the [Stack Overflow Regular Expressions FAQ](http://stackoverflow.com/a/22944075/2736496) for future reference. – aliteralmind Mar 15 '15 at 01:51

1 Answers1

0

/^(?:\d{9}|\d{6}|\d)$/ will check for digits and match if the input is 1, 6 or 9 characters in length.

Regex101 Demo

Ehtesham
  • 2,911
  • 1
  • 14
  • 20