Search code examples
regexdecimalsublimetextnegative-lookbehind

Regex - search for numbers, preceded by a comma or quote, that have no digits before the decimal point


So I've been trying to do a regex in Sublime text on a CSV file to find any number that doesn't have any digits before the decimal point. Basically, I need to find any combinations of ".xx or ,.xx in the document and then add a comma after. I tried attacking it from both the positive end (i.e. any .xx with , or ") and also with a negative lookbehind for .xx that does not have a digit in front of it. Nothing seems to work, but since I'm new to regex I'm sure I have the wrong syntax. Any help would be greatly appreciated.

Right now I have this

(?<!\d)(\.\d{2}) 

which is definitely not working.


Solution

  • Ctrl-H to open Search and Replace, select Regex Search (the icon with .*):

    Search: ([",]\.\d\d)
    Replace: \1,

    This would not check if there is not already a comma after the number. It just added one.

    Tested in Sublime Text 3