[General boards] [Winter 2019 courses] [Fall 2018 courses] [Summer 2018 courses] [Older or newer terms]

Matching the same substring later on twice


#1

One of the questions on the past final was to match this type of string
10110101.00001001.10011001.00110011 —> 01101001.10001000.10110001.00000011

but the first 8 digits of the two IP addresses are the same. I am unsure on how to do that, my idea was
making a capture group ([0|1]{8}) and then doing \1 later on to match it again but that does not work. How are we supposed to make sure they are the same in this situation.


#2

The capture group should work. The only reason it wouldn’t is if you called the wrong group. Groups are labelled in order, from left to right, by their open brackets.

What makes you say that this does not work?


#3

I tried checking with using backreferences and it was not matching: regexr.com/4c10v


#4

In the example you give, the string itself does not have the same first 8 digits for each address. One starts with 10110101 and the other starts with 01101001. These are not the same. So it should not match the regex.


#6

Yea my apologies I just realized why my regex was not working since the provided IP addresses don’t share the first 8 digits, fixed it