Regex101 can get it, but not in Keyboard Maestro

regex101 can get it, but not in Keyboard Maestro

https://regex101.com/r/y8Ayag/1

regex: (?:^|,)(?=[^"]|(")?)"?((?(1)(?:[^"]|"")|[^,"]))"?(?=,|$)
Content :
12312,2.99,AMO024,Title,"Description, more info",,123987564
123,2.99,AMO024,Title,"Description, more info",,123987564
"""test"" test","test""fdas""fdad",

Sceenshot3157846

Usually, when confronted with a regex problem, I try to simplify both the pattern and the input until I get something that works and then build back up from there.

In this case, though, I'm going to suggest you'd be better off abandoning regex entirely. The example data is in CSV format, and there are CSV parsers—like csvkit and Miller, both of which can be installed through Homebrew—that you can use to extract the information. You could even use them to convert the CSV into a JSON file and then do all the processing in Keyboard Maestro.

5 Likes

and also sqlite3, which is part of default macOS distributions (i.e. no need for homebrew)

See, for example:

Querying and Interacting with CSV Files More Easily with SQLite

1 Like

Remember that regular expressions are not well standardized – there's a whole zoo of dialects and different engines.

Hi, @victor_c. I see you are using three regex flags: extended, global, and multi line.

You might the Search Modifiers section on this Regular Expressions wiki page helpful.

For simple use of the built-in sqlite3 tool, which can query CSV data and files directly, see:

Simple querying of CSV with sqlite3 - Macro Library - Keyboard Maestro Discourse

This was hiding in plain sight, but I never used it.

1 Like