Page 1 of 1

Using Lookbehind to remove some information at EOF name

Posted: 2017-10-12 20:56:22
by wolfkin
https://regex101.com/r/IgsZfH/3

This is what I have so far.

SampleFileNames:

Code: Select all

SampleFileA-[SortCode].xls
SampleFileB-[SortCode][CRCNum].xls
SampleFileC-[SortCode][OtherSortCode][CRCNum].xls
SampleFileD-Date[CRCNum].xls
SampleFileE-Date.xls

In this example I only want to remove [CRCNum] from the file names.

This is as close as I can get. I just don't know how to use lookbehind properly
The RegEx

Code: Select all

(?<!\-)\[.+?\](\.\w{3}$)

Code: Select all

$1
The Error

Image

Code: Select all

<RegExp Error> TRegExpr(Comp): Urecognized Modifier (pos 6)
And finally the ideal outcome

Code: Select all

SampleFileA-[SortCode].xls
SampleFileB-[SortCode].xls
SampleFileC-[SortCode][OtherSortCode].xls
SampleFileD-Date.xls
SampleFileE-Date.xls

Posted: 2017-10-13 08:20:00
by antp
What's the "rule" that you try to write?
I do not see the link between your regex and the sample :??:
How could the regex spot the difference between cases A & D ? (i.e. detect what is CRCNum and SortCode)