Reputation: 19320
How does it affect a regex to have it just end with a pipe character?
example :
[0-9]{1,5}|
I know the pipe means or, but in this case it's not "orring" anything. An online tool such as http://regexpal.com/ seems to ignore the extraneous pipe character. Does anyone know if a regex spec can say anything about how a trailing pipe is supposed to be treated?
Upvotes: 1
Views: 1425
Reputation: 784998
Your regex:
[0-9]{1,5}|
is equivalent to:
(?:[0-9]{1,5})?
i.e. match 5 digits or match nothing (empty text).
Upvotes: 0
Reputation: 780798
It's OR
ing with an empty string. So it will match an empty input.
Upvotes: 0
Reputation: 71538
It's still treated as 'or', in your case, it just means it should match 1 to 5 digits, or an empty string.
Note that an empty string can be matched in practically any string.
Upvotes: 4