While replacing using regex, How to keep a part of matched string?

Replace

^(\d+)\.(.*mp3)$

with

\1 \2

Also, in recent versions of notepad++, it will also accept the following, which is also accepted by other IDEs/editors (eg. JetBrains products like Intellij IDEA):

$1 $2

This assumes that the notepad++ regex matching engine supports groups. What the regex basically means is: match the digits in front of the first dot as group 1 and everything after it as group 2 (but only if it ends with mp3)


I tested with vscode. You must use groups with parentheses (group of regex)

Practical example

  • start with sample data
1 a text
2 another text
3 yet more text
  • Do the Regex to find/Search the numerical digits and spaces. The group here will be the digits as it is surrounded in parenthesis
(\d)\s
  • Run a replace regex ops. Replace spaces for a dash but keep the numbers or digits in each line
$1-
  • Outputs
1-a text
2-another text
3-yet more text