ryoishikawa74
ryoishikawa74

Reputation: 177

Regex - Replace numbers with other characters + themselves

I have a document with several 3-digit numbers, example:

blablabla, 305, blabla 401
503 bla bla 708

I need to make them bold, using *number* in a text editor. Is it possible, in Notepad++, to find & replace these numbers and insert the * symbol before and after them? I tried to find in Notepad++ using regex option check for \d{3}, but I don't know how can I replace \d{3} for something like *\d{3}*

Upvotes: 4

Views: 5048

Answers (2)

Rahul
Rahul

Reputation: 2738

Well if the case is only 3-digit numbers then you have to make sure that it doesn't matches numbers like 123 in 1234. For that you have to implement a lookahead for non-digits.

Regex: \d{3}(?=\D) and replacement will be *$0*

Note that the last number 3456 is not matched.

enter image description here

Upvotes: 2

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626747

You may use \d{3} in the Find What field and *$0* in the Replace With field.

The $0 backreference inserts the whole match value.

Note that to only match 3 digit sequences as whole words, you may use \b\d{3}\b where \b stands for a word boundary.

enter image description here

Upvotes: 4

Related Questions