hi All,
I have a regex /(.+)_id$/
in a rails application that matches any string that ends with _id
. I need it to match any string that ends with _id
except associated_id
. How can I accomplish this?
thx :)
-C
hi All,
I have a regex /(.+)_id$/
in a rails application that matches any string that ends with _id
. I need it to match any string that ends with _id
except associated_id
. How can I accomplish this?
thx :)
-C
/(.+)(?<!associated)_id$/
will use negative lookbehind to make sure that whatever was matched by (.+)
doesn't end in associated
.
For languages that don't support lookbehind, you can use this:
/\A(?!.*associated_id$)(.+)_id$/
This will assert that it's not possible to match a string ending in associated_id
from the starting position of the string.
I'm not a "regexpert" so i'm sure there's probably a better way of doing this, but i came up with
/(.+[^associated_id].+)_id$/