-1

Hi this is my example 0xc1e5017fbc68aa3e56aa580708de9aa123d62d18

This is my reg ex ^0x[a-fA-F0-9]{1,40}. What I'm doing is 0x which is compulsory after that we can enter upto 40 alpha numeric digits. But not special characters. What should I do here so it will match correctly?

e.k
  • 1,333
  • 1
  • 17
  • 36

1 Answers1

2

Your issue is that you need to assert where the string ends, or else you will match up until a special character is found, and get undesired matches.

So with your current regex and test string 0xc1!, 0xc1 would be matched, even though it is an invalid match.

How about using: ^0x[a-fA-F0-9]{1,40}$

user3483203
  • 50,081
  • 9
  • 65
  • 94