Reputation: 21
The below regex works on chrome but is having an issue in safari as it contains a lookbehind ,Here in need that lookahead for the proper working so is there any other way by which it could be resolved?
(#[a-zA-Z0-9_(,)]{1,30})+(?<!,)$
The regex im trying to accomplish is :
It should accept:
#tag
#tag_1,#tag2
#tag1,#tag2,#tag3
It should not accept:-
#
#tag(with more than 30 characters)
# tag1,
#tag:///
Upvotes: 1
Views: 61
Reputation: 163277
You can take out the comma of the character class, and prepend it on every iteration
The capture group can be a non capturing one if you need a match only.
^#[a-zA-Z0-9_()]{1,30}(?:,#[a-zA-Z0-9_()]{1,30})*$
The pattern matches:
^
Start of string#[a-zA-Z0-9_()]{1,30}
Match 1-30 repetitions of the character class without the comma(?:,#[a-zA-Z0-9_()]{1,30})*
Optionally repeat ,
and 1-30 repetitions of the character class without the comma$
End of stringUpvotes: 1