Why do the regex patterns '\d+[^-]' behave unexpectedly?

28 Views Asked by At

I am attempting to extract strings that start with any sequence of digits and are followed by any character except '-'

For example, For the string '123-foo', I expect the result to be 'false'. For the string '130 boo', I expect the result to be 'true'. I used the regular expression '\d+[^-]' for this purpose, but it unexpectedly returned both values. However, when I used the regex '\d+[-]', it returned only '123-foo'.

0

There are 0 best solutions below