(\d{1,3}\.){3}\d{1,3}:\d{2,5} 

You can make it so that arbitrary text is added to the expression found on this regex . For example:

 127.0.0.1:8888@blalabla:blablabla 

Not like now:

 127.0.0.1:8888 
  • @lexone, If you are given a comprehensive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky

2 answers 2

Regular expressions do not change the text by themselves. Most engines have a text replacement operation, for example, s/// in Perl, re.sub() in Python.

To add text after the pattern, you can use \K : s/шаблон\K/добавка/ add s/шаблон\K/добавка/ , for example, to add @bla after ip:port in the input text:

 $ echo 'a 127.0.0.1:8888 z' | perl -pe 's/(?:\d{1,3}\.){3}\d{1,3}\:\d{2,5}\K/\@bla/g' 

Result:

 a 127.0.0.1:8888@bla z 

If the regular expression library in this language does not support \K , then you can use group capture (using () ) and refer to the group using $1 , \1 depending on the regexp dialect. Example on Python:

 $ echo 'a 127.0.0.1:8888 z' | python -c 'import re, sys; print(re.sub(r"((?:\d{1,3}\.){3}\d{1,3}\:\d{2,5})", r"\1@bla", sys.stdin.read()))' 

The same result:

 a 127.0.0.1:8888@bla z 

Since \K not used, it is necessary to add \1 to the replacement expression, which inserts the captured text group.

    Try this

     (\d{1,3}\.){3}\d{1,3}:\d{2,5}.* 
    • They did not quite understand me. It is necessary that the text be added to the received regex (it does not exist where we parse). - lexone
    • @lexone I did not quite understand what you want to get in the end. Show some illustrative example. - lampa
    • There is text on page 127.0.0.1:8888 127.0.0.1:1111 122.0.0.1:8888 I need to regularly stretch the values ​​of any line and add my text to it. For example (\ d {1,3} \.) {3} \ d { 1,3}: \ d {2,5} @ my text: my text Sparsit is so 122.0.0.1:8888@ my text: my text is lexone
    • That is, shielding of characters in the regular schedule itself. - lexone
    • Regular expressions are not able to add anything. They check the text for pattern matching. - ReinRaus