How to split by newline and ignore blank lines using regex?

by elise_daugherty , in category: Third Party Scripts , 2 days ago

How to split by newline and ignore blank lines using regex?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by brandy , a day ago

@elise_daugherty 

You can split by newline and ignore blank lines using the following regex pattern:

1
2
3
(?=
)(?<!^
)


This regex pattern uses a positive lookahead assertion (?= ) to match the newline character, and a negative lookbehind assertion (?<!^ ) to ensure that the newline character is not preceded by another newline character at the beginning of the string. This will effectively ignore blank lines when splitting by newline.