Search code examples
phpregexvalidation

Validate that string starts with at least two hyphens then only consists of alphanumeric characters


I have a string that can look in the following ways:

----4dfd650c9f65              match
-----473ffd650c9f65           match
-----473ffd650c9f65s3--       does not match
--473577f2hd650c9f65--        does not match

I would like to match if and only if starts with at least two -- and ends on \n but does not ends with --.


Solution

  • Something like this should work:

    /^-{2,}[0-9A-Za-z]+$/