Regex help

Hi,
I'm confused about how KM is seeing this Regex code. I tried it at regex101 and with the /gm modifier and it does exactly what I want. Why is KM doing something different?
See attached KM file.
I want to capture the name on each line with one comma after it.
I type:
(?m)^[^,]*,
As I understand it, KM should match:
Any number of characters at the beginning of the line that are not commas (possibly 0 of them), followed by a comma.
I expect it to match a comma at the beginning of the line because I used *

However, it seems to be ignoring the beginning of line character and matches any comma on any line.

What am I doing wrong?regex.kmmacros (3.2 KB)

Your RegEx looks OK to me, but your Macro does NOT work because you are using the wrong KM Variable in the For Each Action:

image

You have NOT defined "CsvFile"

Also, your For Each setup is NOT correct. It needs to be on a Lines Collection, like this:

image


  1. ^, ↩︎

oh, sorry, i forgot to change that. I updated it now, but it is still doing the same thing.

regextest.kmmacros (3.3 KB)

Please always post both your macro image and file, as most of us will NOT download the file without seeing the image.

See How to post/upload your macro or script.

Did you make both changes I noted?

Hmm. Well the way you showed above works. I'm wondering why the Substring option doesn't work. It works fine for
(?m)^[^,]+,

When should I use substring and when should I use line?