0

I had a requirement where in my file I had to replace all 2-digitno occurrences to corresponding 3-digitno.

For example:

  • 48 should be replaced by 048.
  • 02 should be replaces by 002.

Till now I am able to identify 2 digit nos in my document with expression:

^[0-9]{2}$

But I am not able to figure out how to append 0 to no. Kindly help me in writing regular expression for this.

Wiktor Stribiżew
  • 484,719
  • 26
  • 302
  • 397
NANCY
  • 61
  • 7

2 Answers2

2

You can simply replace the result of following regex :

/\b(\d\d)\b/g

to :

/0\1/ 

or for capturing the group in some regex engines use $1

kasravnd
  • 94,640
  • 16
  • 137
  • 166
1

Use this in the Search and Replace dialog:

Find what:      \b\d{2}\b
Replace with: 0$0

Note that ^[0-9]{2}$ means match 2 digits from the beginning of the line till end. So, if you have several numbers and not equaling the whole line, your regex would not work.

\b is a word boundary, and makes sure there is a letter, digit or an underscore before/after the word.

enter image description here

Wiktor Stribiżew
  • 484,719
  • 26
  • 302
  • 397