75

I have

12.hello.mp3
21.true.mp3
35.good.mp3
.
.
.

so on as file names in listed in a text file.

I need to replace only those dots(.) infront of numbers with a space.(e.g. 12.hello.mp3 => 12 hello.mp3). If I have regex as "[0-9].", it replaces number also. Please help me.

1

4 Answers 4

107

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)

Sign up to request clarification or add additional context in comments.

3 Comments

@Doug Yes, the groups are defined by the paratheses
Thanks a lot, I didn't even knew that this was possible with regex
Thanks. But to match all lines, it worked for me without using ^. Or it would only match first line. Tested on regexr.com
8

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

1 Comment

thanks! the parenthesis was what i was forgetting for vs code
1

The answers here didn't make much sense to me and took me a while to figure things out.


Let's say I have this string:

  • return this.logSomething('text');

and I want to turn it into this:

  • this.logSomething('text'); return;

...then this is what the find field should contain:

  • return (this.logSomething\('[a-zA-Z0-9]*'\);)

and this is what the replace field should contain:

  • $1 return;

The insight here is the additional parentheses within the find field. They delimited your groups, which you then reference with $1, $2, and so forth.

Comments

-1

Using the basic pattern, well described in the accepted answer here is an example to add the class="odd" and class="even" to every <tr> element in Notepad++ or any other regex compatible editor:

Find what: (<tr><td>)(.*?\r\n)(<tr><td>)(.*?\r\n)

Replace with: <tr class="odd"><td>\2<tr class="even"><td>\4

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.