Skip to main content
Chris Panny
Inspiring
April 6, 2017
Answered

Help With Grep Positive Look Behind

  • April 6, 2017
  • 3 replies
  • 2063 views

Windows 10 64 bit, InD CC 2107

I'm working on an ePUB doc and I have to find a tab character within a specific, yet consistent text pattern and swap the tab for a space character. It always starts at the beginning of a paragraph, with a digit followed by a period mark. It may include some repetition of these characters like so:

3.4.1.4.5 tab more alpha text

I start my Grep like this just to see if it's working:

^\d\.[\d\.]*\t

which it does.

But when I try to load everything but the tab character into Positive Look Behind, but it doesn't find the tab:

(?<=^\d\.[\d\.]*)\t

What am I doing wrong?

This topic has been closed for replies.
Correct answer Obi-wan Kenobi

(?-s)^(\d+\.?)+\K\t

(^/)

3 replies

Chris Panny
Inspiring
April 6, 2017

I tried leaving out the carrot ^, but I get: Cannot Find match.

I tried \K. It behaves the same way as ^\d\.[\d\.]*\t, meaning it finds and selects all of the characters, which isn't quite what I'm looking for. I need to isolate the tab after the digit(s) and period mark(s) and then swap it out with a space character. That's why I'm pretty sure I need Pos Look Behind - look behind the tab, confirm a match and then swap.

I have a feeling these characters that need to go inside Pos Look B-hind, need to get enclosed in something - brackets, curly braces, or parenthesis - I tried these but it didn't work. Maybe some combo of these?

It's only an island if you look at it from the water.
Obi-wan Kenobi
Obi-wan KenobiCorrect answer
Brainiac
April 6, 2017

(?-s)^(\d+\.?)+\K\t

(^/)

Chris Panny
Inspiring
April 7, 2017

Obi,

thanks - it worked!

Big thanks to everyone else for their input!

It's only an island if you look at it from the water.
winterm
Brainiac
April 6, 2017

Try use \K instead of (?<=)

About \K usage you can read here (post 14 and further)

Mike Witherell
Adobe Expert
April 6, 2017

Did you try leaving out the ^ carat from the positive look-behind?

Mike Witherell