Can anyone help me create a regular expression that accepts alphanumeric (numbers and letters only) and dashes and white spaces.
It shouldn’t accept consecutive dashes and consecutive white spaces. or a dash followed by a white space and vice versa.
It should always begin and end with alphanumeric characters as well.
Thank you so much. Any help would be very much appreciated. (^-^)v
'Abcde' , '324 3a-32' : valid
'-' , '324 3a - 32' , '-2323 d-', 'z- -a' : invalid
Thanks guys for all your help. v(“,)\
Try this:
When the first
[A-Za-z0-9]+runs out of letters and digits, the[\s-]inside the group tries to match a hyphen or a whitespace character. If it succeeds, the second[A-Za-z0-9]+tries to match some more alphanumerics. And the group gets repeated as many times as necessary.