Match the same number of characters as the previous group

Basically, I need a combination of \kand \g.

Here is an example:

I have lines in the form "123045 ; 67089". I should correspond to this only if in both numbers there is a repeating digit in the same position relative to the end of the number. In this case, 0in 123045is in two positions from the end of the number, as is 0in 67089.


The problem is that if I use backlinks, all the remaining numbers must match (aka 45c 89):

^\d*(\d)(\d*) ; \d*\1\2$

And if I use re-execution of the template, I must indicate the remaining number of characters (in this case, two):

^\d*(\d)(\d{2}) ; \d*\1\g<2>$

Yes, it should be in one regular expression.

+4
1

, , - . , :

^\d*(\d)(?:(\d(?:(\s*;\s*\d*\1)|\g<2>)\d)|\g<3>)$

\s*;\s*\d*\1 . , ( , 122 12;1;13). - , .

+3

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


All Articles