• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help With Grep Positive Look Behind

Engaged ,
Apr 06, 2017 Apr 06, 2017

Copy link to clipboard

Copied

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?


It's only an island if you look at it from the water.

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 06, 2017 Apr 06, 2017

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

(^/)

Votes

Translate

Translate
Community Expert ,
Apr 06, 2017 Apr 06, 2017

Copy link to clipboard

Copied

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

Mike Witherell

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Apr 06, 2017 Apr 06, 2017

Copy link to clipboard

Copied

Try use \K instead of (?<=)

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 06, 2017 Apr 06, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 06, 2017 Apr 06, 2017

Copy link to clipboard

Copied

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

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 07, 2017 Apr 07, 2017

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines