0

i'm trying to apply a certain formatting using InDesign GREP-Styles. My intention is to match every first line of a paragraph.

My first attempt was:

(?<=\r)(\w)+(?=\r)

but this won't work and if it would, then the very first paragraph wouldnt match. Has anybody an idea? My regex skills are very, very poor...

For better understanding:

Lorem ipsum dolor sit amet
Sed diam nonumy eirmod tempor

Lorem ipsum dolor sit amet
Sed diam nonumy eirmod tempor

Lorem ipsum dolor sit amet
Sed diam nonumy eirmod tempor

should become

*Lorem ipsum dolor sit amet*
Sed diam nonumy eirmod tempor

*Lorem ipsum dolor sit amet*
Sed diam nonumy eirmod tempor

*Lorem ipsum dolor sit amet*
Sed diam nonumy eirmod tempor
Francis
  • 244
  • 1
  • 4
  • 14

2 Answers2

1

Did you try this:

(?<=\r\r|^\r|^)(.*)

(a lookbehind must be with fixed length (except in .net), however several regex engines allow to use alternations inside)

If it doesn't work, you can use a capturing group:

(\r\r|^\s*)(.*)

or

(~b~b|^~b*)(.*)

and replace the match by:

$1*$2*
Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
1

If I'm not mistaken, putting a ^ at the beginning of the grep will force it to match the beginning of a paragraph (at least it does in my CS5).

However, if you have an achored object at the start of your paragraph, you can't grep it as an anchored object, instead, you grep it with a wildcard - just a . will do.

So, if you want to find [anchoredObject]Lorem

Then you would grep with this: ^.L

or something like this: ^.\t[\l\u]+ which will grep the very first word of the paragraph, if it begins with an anchored object followed by a tab. The [\l\u] will match "any letter".

But if you just want to do the first line, why not use a Nested Line Style (under "Drop Caps and Nested Styles" in "Paragraph Style Options". There you can actually choose what to do for the first line, even if the line is not broken by a break.

bgmCoder
  • 6,205
  • 8
  • 58
  • 105