#1 2023-01-25 01:07

visusys
Member
Registered: 2021-10-16
Posts: 10

Lookaround TRegExpr Compile Errors

I am trying to utilize lookaround to separate digits with periods, but only in certain circumstances.

My exact goal is here (this is my post): https://stackoverflow.com/questions/752 … 2#75228472

The first response gave me the following solution:

Expression:

(?:(?<=\s)|(?<=\sv))(\d+)\s(?=\d)

Replace:

$1.

Unfortunately I am getting an error in Renamer.

TRegExpr compile: lookaround brackets must be at the very beginning/ending (pos 4)

mini_ReNamer_FU12Xkel8o.png

Can someone explain to me how I can get this expression to work?

Or what regex engine that ReNamer uses so I can ask for more specific help on stackoverflow?

Any help at all would be great.

Offline

#2 2023-01-25 15:54

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,284

Re: Lookaround TRegExpr Compile Errors

Regarding the error message:

TRegExpr compile: lookaround brackets must be at the very beginning/ending (pos 4)

This is a known limitation of the regex engine, as documented here:
https://regex.sorokin.engineer/en/lates … assertions

Brackets for lookahead must be at the very ending of expression, and brackets for lookbehind must be at the very beginning. So assertions between choices |, or inside groups, are not supported.

It should be possible to achieve the same result with multiple rules or pascal script.

Offline

#3 2023-01-29 02:43

visusys
Member
Registered: 2021-10-16
Posts: 10

Re: Lookaround TRegExpr Compile Errors

den4b wrote:

Regarding the error message:

It should be possible to achieve the same result with multiple rules or pascal script.

If you don't mind, this is the expression that I want to get working the most:

https://stackoverflow.com/questions/752 … 3_75228498

Expression:

(?:HoRNet|more|exceptions|here)(*SKIP)(*F)|(?<=[a-z])(?=[A-Z]\B)

Replace:

(A space)

Do you know how I can get this working through usage of multiple rules or PascalScript?

The expression separates CamelCase similar to the clean-up function, but allows for a "whitelist" that when encountered doesn't get modified.

Does PascalScript utilize a more robust RegEx engine? If so, can I invoke more advanced RegEx expressions through PascalScript?

Any help at all would be greatly appreciated.

Offline

#4 2023-01-31 00:48

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,284

Re: Lookaround TRegExpr Compile Errors

This script for the Pascal Script rule should do it.

List all your special cases in the Exceptions constant. You will need to use at least ReNamer 7.4.0.2 Beta.

const
  Exceptions = 'HoRNet|more|exceptions|here';
var
  Positions: TIntegerArray;
  Matches: TWideStringArray;
  I, NumMatches, PositionAnchor: Integer;
begin
  PositionAnchor := Length(FileName);
  NumMatches := FindRegEx(FileName, '(?<=[a-z])(?=[A-Z]\B)', True, Positions, Matches);
  for I := NumMatches - 1 downto 0 do
  begin
    if Positions[I] <= PositionAnchor then
    begin
      Insert(' ', FileName, Positions[I]);
      Matches := MatchesRegEx(Copy(FileName, 1, Positions[I]-1), '(' + Exceptions + ')\Z', True);
      if Length(Matches) > 0 then
        PositionAnchor := Positions[I] - Length(Matches[0]);
    end;
  end;
end.

Example input:

HoRNetCompExp_x64
HoRNetDynamicsControl_x64
HoRNetHarmonics_x64
HoRNetHTS9_x64
HoRNetMulticompPlusMK2_x64
HoRNetSongKeyMK3_x64
HoRNetTape_x64
HoRNetValvola_x64

Example output:

HoRNet Comp Exp_x64
HoRNet Dynamics Control_x64
HoRNet Harmonics_x64
HoRNet HTS9_x64
HoRNet Multicomp Plus MK2_x64
HoRNet Song Key MK3_x64
HoRNet Tape_x64
HoRNet Valvola_x64

Offline

#5 2023-01-31 04:18

visusys
Member
Registered: 2021-10-16
Posts: 10

Re: Lookaround TRegExpr Compile Errors

Awesome! Thank you so much! I'll be including that in my preset now, you're a lifesaver.

Offline

#6 2023-02-01 03:24

visusys
Member
Registered: 2021-10-16
Posts: 10

Re: Lookaround TRegExpr Compile Errors

den4b wrote:

This script for the Pascal Script rule should do it.

List all your special cases in the Exceptions constant. You will need to use at least ReNamer 7.4.0.2 Beta.

Hi again, I just got around to testing the script.

While it works if an exception occurs at the beginning of the filename with no spaces, it falls apart if the exception occurs anywhere else in the string. See this image:

dFg42T4.png


Input:

ExceptionTwoTest
ExceptionTwo Test
Test ExceptionTwo
Test ExceptionNumOne
ExceptionNumOneTest
ExceptionNumOne Test

Correct Output:

ExceptionTwo Test
ExceptionTwo Test
Test ExceptionTwo
Test ExceptionNumOne
ExceptionNumOne Test
ExceptionNumOne Test

Actual Output:

ExceptionTwo Test
Exception Two Test
Test Exception Two
Text Exception Num One
ExceptionNumOne Test
Exception Num One Test

I think it has to do with the regex. I'm not sure how to modify it though to fix the issue. I'll keep experimenting.

If you happen to know a fix that would be great!

Offline

Board footer

Powered by FluxBB