Insert 0 when you have 10 numbers

Asked

Viewed 90 times

2

I have the following sequence:

3531399402

It has 10 numbers, with this regex I can list these occurrences:

^\d{10}$

I am using a text editor and I need to replace these occurrences and insert a 0 before getting like this:

03531399402

How can I do ?

  • Which editor? Notepad++? Eclipse?

  • 1

    Sublime Text is the editor.

  • An alternative is to put everything into a grouping and use the retrospective, something like s/^(\d{10})$/0\1/

  • I did not understand rsrs well, and I glued here and it did not function.

  • 1

    Boot in the research ^(\d{10})$ (same as your example, but with a parenthesis around the characters); in the substitution field by 0\1; that \1 is a retrospection component, will be replaced by the contents of the first group.

1 answer

5


You must enter a capture group.
So you can identify replace through the group and use it again with what you want to insert.
I suggest you try to change your regex to:

^(\d{10})$

And use for replace:

0$1

This indicates that replace should be done by inserting 0 and capture group 1 which in this case are the 10 digits you mentioned in the question.

  • Show, thank you very much.

  • 1

    The use of () ?

  • @Douglas is mandatory, because the substitution depends on the capture group, which is indicated by "()", without this the "$1" would not indicate anything, because there would be a group 1.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.