(image) how to find the green highlight part using regex?
regex101 https://regex101.com/r/knSRpd/3
where i think the problem lay at: is i used the lookahead to find the next line that didnt start with Tab. what I had tried: ^(?!\t)(^(FULL|SMALL))?(\S.\n$)?(\S.*?)(?=^(?!\t)\w ?|$(?!\n))
I tried to find the string sentence in between with end of line at \n (\S.\n$)?
CodePudding user response:
If you want to find all lines after FULL or SMALL that do not start with a tab:
^(FULL|SMALL)\b(.*(?:\n(?!\t).*)*)
^
Start of string(FULL|SMALL)\b
Capture either FULL or SMALL in group 1(
Capture group 2.*
Match the rest of the line(?:\n(?!\t).*)*
Optionally repeat matching the next lines if they don't start with a tab
)
Close the non capture group
In the replacement, use group $1
and group $2
If you only want to match lines that start with a non whitespace char to prevent matching empty lines
^(FULL|SMALL)\b(.*(\n\S.*)*)
CodePudding user response:
You can use
/^(FULL|SMALL)\b(.*(?:\n(?!\t|FULL\b|SMALL\b).*)*)/gm
/^(FULL|SMALL)\b(.*(?:\n(?!\t).*)*)/gm
The replacement will need adjusting (since there are just two capturing groups in the pattern now) to
<div class="PANEL $1">\n<div class="action">$2</div></div>\n\n
See the regex demo. Details:
^
- start of string(FULL|SMALL)\b
-FULL
orSMALL
as whole words(.*(?:\n(?!\t|FULL\b|SMALL\b).*)*)
- Group 2:.*
- the rest of the line(?:\n(?!\t|FULL\b|SMALL\b).*)*
- zero or more lines that do not start with a TAB,FULL
orSMALL
as whole words. If you use(?!\t)
, the checks forFULL
andSMALL
will not be triggered and even if the line starts with these words, it will get consumed.