Deeply nested groups in RegEx

I answered one question and I received a comment from tenub.

Comment:

Do you need to use $ {1} 000 since the pre-added content consists of numbers?

So, if I use this regex. (Do not look at practicality, this is intentional for this question)

^(((((((((((.{3})))))))))))

So, the line "some string".Groups $1to $11contains. "som".

Now, if I wanted to replace the above line with some1, I would do the normal job:

$11 // Group 1 followed by my replace string "1"

But this corresponds to the group 11, which is also represented $11.

I know about callback functions, but I need to know if any particular regular expression exists.

So my questions are:

  • - , 1 Group11, ​​$11
  • regex. ?
+4
1

0 , . MDN 1 2 .

"some string".replace(/^(((((((((((.{3})))))))))))/, '$011'); 
\\ => "som1e string"
+3

Source: https://habr.com/ru/post/1534876/


All Articles