postgresql – Syntax battle using Postgres regex in query
In addition to solution in other answer, it’s good to understand that regex matches text, if the text contains any substring matching the pattern.
From what you are saying, it seems to me that you think that regex should just match entire string be default, which is not true.
Your pattern matches 1-1-1-2 followed by + zero or more times. So it would even match string like
whatever 1-1-1-2 whatever
As suggested you would need to use anchors to indicate in regex that you want to match start and end of string.
But in addition to that, you could generalize your pattern: match 1-1-1-2 that is followed by non digit, like ^1-1-1-2\D?$ (regex 101). \D matches non-digit character.
Read more here: Source link
