Using Lookbehind to remove some information at EOF name

If you need help on how to use the program
Post Reply
wolfkin
Posts: 2
Joined: 2014-06-18 16:03:52
Location: Toronto, On

Using Lookbehind to remove some information at EOF name

Post 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
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post 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)
Post Reply