I want a regex to match identifiers consisting of letters, digits and _, without double underscores. My current attempt:^(?!_)(?!.*?_$)[a-zA-Z][a-zA-Z0-9_]+$Example:Abdfsdfsdf__ 1B2345_v1__23456__23456789b12345-67891234567891_fsdfdfsdfv_fsdfsdf_fsdfdv_123v__123v134234_fsdfsd123456a1b2c3d4e5Matched:v1__23456v_fsdfsdf_fsdfdv_123v__123v134234_fsdfsda1b2c3d4e5How can I remove the rows v1__23456 and v__123 from the matches?
regex to match identifiers without double _
regular expression
^(?!_)           # don't start with _(?!.*?_$)        # don't end with _[a-zA-Z]         # the first character must be a letter[a-zA-Z0-9_]+$   # after that digits and underscores are okYou've expressed in two different ways that the first character must not be _, but nothing here says anything about __ in the middle.Using negative lookahead, it is simple to express one or more alphanumeric characters or _, don't start with _ or a digit, don't end with _, and don't allow __ anywhwere:^(?![0-9_]|.*__.*_$|)[0-9A-Z_a-z]+$Without negative lookahead (e.g. in awk or grep -E), you can split the pieces:^[A-Za-z][0-9A-Za-z]*(_[0-9A-Za-z]+)*$Start with a letter, then zero or more alphanumerics, then you can have underscores but each one must be followed by one or more alphanumerics.