0

I've tried searching for this, but couldn't find one that worked for what I needed it for.

I'm trying to find [DLC] in a line, and move it to the end of that line.

ShidaPenns
  • 11
  • 1

1 Answers1

2

You can try this regex:

^(.*?)(\[DLC\])(.*)$

and replace with

$1$3$2

Explanation:

The regex splits the string into three groups:

  1. everything before [DLC]
  2. [DLC]
  3. everything after [DLC]

and reorders the groups in the order of 1, 3, 2

Demo

Sweeper
  • 213,210
  • 22
  • 193
  • 313
  • Notepad++ uses backslash for escaping group numbers. – Eduard Jul 15 '18 at 09:01
  • @Sedo no I checked the wiki. $ is okay: http://docs.notepad-plus-plus.org/index.php/Regular_Expressions#Substitutions – Sweeper Jul 15 '18 at 09:02
  • @Sedo: It did, but it's very old, about 10 years ago! – Toto Jul 15 '18 at 09:35
  • Please explain why the `?` is needed there? – sandthorn Jul 15 '18 at 09:42
  • 1
    Without the question mark, group 2 will capture the last occurrence of [DLC], with it, the first occurrence will be captured. @sandthorn – Sweeper Jul 15 '18 at 09:44
  • May I say like `?` turns greed into ample greed? – sandthorn Jul 15 '18 at 09:53
  • @sandthorn it’s called lazy. see [this post](https://stackoverflow.com/q/2301285/5133585). Actually I was wrong. Without the ?, the regex will capture everything in the first group. – Sweeper Jul 15 '18 at 09:55
  • I guess not. Your first explaination is totally correct, without `?` , group 1 will be expanded, greedily, until the last occurance of [DLC]. – sandthorn Jul 15 '18 at 10:14