I have list (multiline text string) with same number of line (order of items may differ in many ways and numbers of line may be however):
Ardei
Mere
Pere
Ardei
Castraveti
I want to find 2 th occurrence of a match line that contain ‘Ardei‘ and replace name of item with another name and, separately in another regex, find 1 st occurrence of ‘Ardei‘ and replace name with something else (perl).
Let’s say you want to replace the 2nd
"Ardei"with"XYZ". You could do that like this (PCRE syntax):and replace it with:
The
$1contains everything that is captured in(.*?Ardei.*?)and the(?s)will cause the.to match really every character (also line break chars).A little demo:
will print: