1

I tried inserting special characters *, +, ?(lazy) into lookbehind expression in regex, but resulted in invalid regular expression.

Example text source

\APPS\MCCSDOCS\GENERAL\10-11 ARRAT\BRIDGE RIVER_\BRIDGE RIVER-PA0900021_DEC 21.PDF   
\APPS\MCCSDOCS\GENERAL\10-11 ARRAT\BURNS LAKE\BURNSLAKE_PA1100062-SE_MAR2010.XLS   
\APPS\MCCSDOCS\GENERAL\10-11 ARRAT\CAMPBELL RIVER\CAMPBELLRIVER_PA0900004_ARRAT_OCT2010.PDF   

Tried regular expressions

(?<=arrat.+?)\.pdf
(?<=arrat.*?)\.pdf
(?<=arrat.+)\.pdf
(?<=arrat.*)\.pdf

all resulted in "invalid expression" in notepad++7.5

So I tried escaping the special characters like follows

(?<=arrat.\+\?)\.pdf
(?<=arrat.\*\?)\.pdf
(?<=arrat.\+)\.pdf
(?<=arrat.\*)\.pdf

then, all resulted in "Can't find the text"

In fact, now I'm using "\K" for the similar effect to the above regular expression in lookbehind search.

Therefore, I'm curious about if it is impossible to use above special characters in lookbehind search, otherwise if there are other ways to use lazy search in lookbehind.

Thm Lee
  • 1,212
  • 1
  • 5
  • 11
  • 1
    Here's a good reference on lookarounds: https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean – denvercoder9 Mar 18 '18 at 06:24
  • 2
    [Variable-length lookbehinds aren't generally supported](https://stackoverflow.com/q/22821644/7586). What are you trying to do? Why are you matching just the extension? Usually you can avoid this by capturing, and using the captured group as part of the replace. – Kobi Mar 18 '18 at 06:25
  • Thanks for your answer. I understand it now:-) – Thm Lee Mar 18 '18 at 06:37

0 Answers0