Copy link to clipboard
Copied
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?
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)
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
Huh - I was sure I'd tried that without success, but I copy-pasted your code and it does indeed work exactly as required - thank you.
I have two correct solutions now, which solves my problem totally - but still no understanding of why my original code doesn't work. A bug, perhaps?
Copy link to clipboard
Copied
PraxisCreativeArt wrote
[…] I have two correct solutions now, which solves my problem totally - but still no understanding of why my original code doesn't work. A bug, perhaps?
Strange... I might be overlooking something, but I can't figure it out either. I tried the reverse
(?<=\r)\r
and indeed that works as expected. So, next I tried this one
(?<=[^\r])\r
and … it finds what you are looking for! There are a few flags that deal with "multi-line" and "single-line" stuff, but I don't think they have an influence in this scenario.
This code is slightly different from your (?<!\r)\r, as it does not find "a return where there is no return before", but rather it finds "a return where there is a character before which is not a return". (The difference is in the behavior when there is no character before the return; yours will should match, mine would not.)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now