I have been trying to come up with a RegEx that would match numbers (including decimals and negative numbers) that are not preceded by a specified set of characters. For example:
Specified set of characters (not including comma): c, t
Input string: “This c2 is one element. And t-4a, d25, c2.54, v4.28, q58 are other elements”
Desired result (the numbers not preceded by c and t):
The pattern I tried: [^ct](-?\d+\.?\d*|\.\d+)
The matches I got (Note: I fetched the results from Group 1):
I don’t want the numbers in bold to be returned since in t-4a the integer -4 is preceded by t, and in c2.54, 2.54 is preceded by c.
Can we refine the above pattern or is it even possible?
View Complete Post