Named Groups/Backreference Support?

A swapping-ground for Regular Expression syntax

Named Groups/Backreference Support?

Postby wolgan » Sun Apr 21, 2024 8:47 pm

TL;DR: Does BRU support named backreferences in any form or style?

Based on my experimentation, it seems BRU does not support regex named backreferences in replacement strings. However, I'm a relative amateur, so I could just be overlooking something simple, so figured I'd asked here before I gave up. :)


I am using version 3.4.4.0 of BRU.

I've tried using both PCRE2 and Boost style named back references, and both work fine when I tested them in regexbuddy, but neither function correctly in BRU (and yes I've got the v2 option checked). Using the search expression without named groups, aka just using standard numbered backreferences works fine, so my match string is good.

My regex search string (this is the style of named group the BRU help file indicates should be used, via both the PERL and Boost syntax guides it links to)
Code: Select all
(?<Y>\d{4}) (?<M>\d{2}) (?<D>\d{2}) (?<Title>.*?)\[(\d+ ?( ?Gif|Clip|Pic|Vid)s? ?)* (?<Tag>.+)\](?<PostID>_.*)

I have tried (among others), the following replacement string. It shows the replacement string literally in the new file name field.

Boost (This is the style that the BRU help file indicates should be used, via both the aforementioned PERL guide and the Boost Replace Format String Syntax guide)
Code: Select all
$+{Tag}_$+{Y}-$+{M}-$+{D}_$+{Title}$+{PostID}
wolgan
 
Posts: 2
Joined: Sun Apr 21, 2024 8:15 pm

Re: Named Groups/Backreference Support?

Postby wolgan » Sun Apr 21, 2024 9:06 pm

...and I was right about it being something simple. Somehow the v2 box got unchecked while I was testing. I'll take my idiot hat and go sit in the corner.

This syntax works as designed.

Search String:
Code: Select all
(?<Y>\d{4}) (?<M>\d{2}) (?<D>\d{2}) (?<Title>.*?)\[(\d+ ?( ?Gif|Clip|Pic|Vid)s? ?)* (?<Tag>.+)\](?<PostID>_.*)

Replace String:
Code: Select all
$+{Tag}_$+{Y}-$+{M}-$+{D}_$+{Title}$+{PostID}


Since there wasn't another post regarding named backreferences that had a definitive answer, I'll leave my post up here so others can learn from my mistakes. :D
wolgan
 
Posts: 2
Joined: Sun Apr 21, 2024 8:15 pm

Re: Named Groups/Backreference Support?

Postby Admin » Tue Apr 23, 2024 5:37 am

Hi , thank you for posting! Yes, they are supported in version 2 of the RegEx, so it needs that checkmark enabled. 8)
Admin
Site Admin
 
Posts: 2579
Joined: Tue Mar 08, 2005 8:39 pm


Return to Regular Expressions


cron