I have a column with values that identify if it contains any string values and then leaves them alone and if it contains any numbers, it treats them further down the flow.
from
49-351
and
123.33
1.3
9.99
abcde
1234
I want to identify
49-351
and
abcde
I am unable to handle the exceptions.. please find the regex demo
CodePudding user response:
You could take the opposite approach and just match something that isn't a number using this regex:
^(?!\d (?:\.\d )?$).*$
This regex uses a negative lookahead to assert that the string as a whole doesn't match digits (\d
) followed by an optional decimal point and more digits (\.\d
).
CodePudding user response:
Part of the problem is that various languages treat the regex patterns differently. Thus, there are changes to the pattern depending on the language's implementation of regular expressions.
For Go, your expression would be: ([a-z] )|(\d -\d )
If you are matching the string 49-351
then that's all you need in the expression. If you want to match digits and associated symbols in general, you would use [0-9.-]*
, which would match digits, period, and hyphen.
For letters, you would use [a-z]*
as the expression. Or [A-Za-z]*
for upper and lower case. Brackets show that a range of characters will be matched, but the meta characters like \d
depend on the regex implementation.