Skip to main content
Participant
February 12, 2019
Answered

Need GREP negative lookbehind syntax guidance

  • February 12, 2019
  • 1 reply
  • 1587 views

I have a bunch of text verses to import. Each verse is 4 lines, each a paragraph on their own with a carriage return at the end. In between each verse is an extra carriage return to space it.

All things bright and beautiful,

all creatures great and small,

all things wise and wonderful,

the Lord God made them all.

Each little flower that opens,

each little bird that sings,

He made their glowing colours,

He made their tiny wings.

All things bright and beautiful,

all creatures great and small,

all things wise and wonderful,

the Lord God made them all.

The purple-headed mountain,

the river running by,

the sunset and the morning,

that brightens up the sky;

I'm trying to simplify this by converting all the carriage returns at the end of the first three line to line feeds. After that i'll remove the excess carriage return between the paras and use paragraph spacing instead.

I'm trying to come up with the appropriate GREP formula to first the first three lines' carriage returns, and the best i can come is  (?<!\r)\r which i *think* means "find all carriage returns that aren't preceded by another carriage return" (and then convert to a line feed) But it's finding ALL carriage returns, including the two in a row at the end of each verse. What am I missing?

This topic has been closed for replies.
Correct answer vladan saveljic

if you want to make grep with negative lookbehind, try this:

(?<!^)\r

(find all carriage returns that aren't at the beginning of the paragraph)

1 reply

Community Expert
February 12, 2019

I have not been able to make the \r work with negative lookbehind andi am also getting the same results as you, maybe someone will pitch in with more insight. But what you are trying to do can be done without lookbehind as well, if i understand it correctly. Try the following in find grep

Find What

([^\r])\r

Change to

$1\n

-Manan

-Manan
Participant
February 12, 2019

Hey, that's clever :-) Didn't occur to me to use the (not a member of set) construction. Yes, this does what I need it to do, thank you. Would still like to know why the lookbehind isn't working though.

vladan saveljic
vladan saveljicCorrect answer
Inspiring
February 12, 2019

if you want to make grep with negative lookbehind, try this:

(?<!^)\r

(find all carriage returns that aren't at the beginning of the paragraph)