I need a regular expression to match line 3 in some text. I have tried this:
\A(?:^.$\n){3}\K^.$
But that didn't work. Any ideas how I can match line 3?
I need a regular expression to match line 3 in some text. I have tried this:
\A(?:^.$\n){3}\K^.$
But that didn't work. Any ideas how I can match line 3?
See:
and
Have a look at this macro that extracts any specified line from a list:
Keyboard Maestro directly supports:
So, without adding a regular expression as a further problem:
Third line.kmmacros (3.4 KB)
It is a shame one of those delimiters cannot be directly a new line \n
(Although @peternlewis has hinted that this might be implemented one day...)
As a variation of of your solution I have been using the below a lot recently as it forces \n to work as a delimiter. It allows me to see at a glance that I am getting the nth line from a Variable).
EXAMPLE Get Line 3.kmmacros (3.7 KB)
EDIT - And it's worth pointing out that in this Keyboard Maestro native method the number in the square brackets can also be a Variable:
So, if a Variable LOCAL__Number was set to "4" it would get line 4.
%Variable%LOCAL__Variable(LOCAL__Number]\n%
Or in @ComplexPoint's version
%Variable %local_Delimited[LOCAL__Number]~,~%
If we're playing, here's one using shell script actions that will also return +ve and -ve (counting from the end) lines:
Get Line.kmmacros (6.3 KB)
Hey Ross,
This question has come up a number of times on the forum. Here's one example:
Feature Request: Filter or Token: "nth Line"
Your regular expression above is not correct for the task at hand.
Here's one that works.
-Chris
Many thanks for your excellent help as usual.