I noticed that one of my macros using a regex wasn't working properly, using Search/Replace action. I created a simple macro to demonstrate the behaviour, with the following regex:
I get the same result with: ^([^\n]+?)\n
Unless my regex understanding is faulty (which is possible!), it seems that this regex may be looping through multiple times. As far as I understand, either of these expressions should only remove the first line, but it seems to be removing all lines up until the last line.
Again, I'm not regex-pert but thought I should mention this just in case it's a bug, as this expression is behaving differently than in KM7. Thanks in advance!
ps. as a successful workaround, I wrote the following expression to split everything into 2 groups using the "search variable" action – 1) the first line and 2) all the following lines
@peternlewis and @ccstone are the master RegEx gurus around here, so they may have a better solution.
Here's an example macro to remove the first line.
Please let us know if this answers your question, and feel free to ask any follow-up questions.
RegEx is a complicated topic, and we all (certainly I do) learn from our discussions.
It does loop through multiple times because it is a global search and replace, but you’re not wrong, the behaviour is incorrect because the ^ should only be matching at the start of the entire string unless you use the (?m) flag.
Wow, thanks so much, @JMichaelTX and @peternlewis. Always so impressed by JMichael’s clear explanations and all the time spent with examples, I’ve learned a lot already by reading it a few times through. This kind of support and problem solving would be a great service to offer as a recurring, premium membership, just sayin’ KM is essential to a lot of what I do to make a living, so great to have this support.
No problem about changing the title, the original default one was an oversight on my part. I scrapped my original forum post with a better title after deciding to use KM’s “Share” feature.
Peter mentioned the (?m) flag. Anyone know off hand a good explanation of these and their usage in KM? I tried a forum search but couldn’t find anything relevant, and I’m not sure what the general term for these things are.
m – Control the behavior of “^” and “$” in a pattern. By default these will only match at the start and end, respectively, of the input text. If this flag is set, “^” and “$” will also match at the start and end of each line within the input text.
Peter, I’m sure you hate this question, but with 0% pressure and 100% humility, do you have rough ETA for 8.0.3? Wondering if it’s worth me adjusting all of my frequently-used macros that are affected by this temporary ^ behaviour. Even knowing if it’s a matter of days, weeks or months would be enough for me to make a decision
The following flags control various aspects of regular expression matching. The flag values may be specified at the time that an expression is compiled into a RegexPattern object, or they may be specified within the pattern itself using the (?ismx-ismx) pattern options.