MRT: Search/Replace nth occurrence of a char or string.

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
PRSchwob
Junior Member
Junior Member
Posts: 6
Joined: 2010-09-17, 03:29 UTC
Location: Palo Alto, CA, USA

MRT: Search/Replace nth occurrence of a char or string.

Post by *PRSchwob »

I have a long list of filenames with <variable length string>-<variable length string>-<variable length string>.ext, and I wish to replace the first "-" with "--" in all these filenames.
Can someone give me a hint on how to replace only the nth (in this case, the first) occurrence of a character (or string)?
Many thanks!
User avatar
petermad
Power Member
Power Member
Posts: 14796
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Search/Replace nth occurrence of a char or string.

Post by *petermad »

This seems to do it for your example:
Search for:

Code: Select all

(.+?)-(.+)
Replace with:

Code: Select all

$1--$2
[x]RegEx
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
PRSchwob
Junior Member
Junior Member
Posts: 6
Joined: 2010-09-17, 03:29 UTC
Location: Palo Alto, CA, USA

Re: Search/Replace nth occurrence of a char or string.

Post by *PRSchwob »

Brilliant! Many thanks!
Post Reply