0

Does a backreference of a special character "(.)" the period mean that what ever the special character was at the time of running the backreference will copy it?

Ie. Is a backreference always a copy of the group regardless of what's inside the brackets?

alwayscurious
  • 1,155
  • 1
  • 8
  • 18
  • 1
    Your question is little unclear. But generally backreference doesn't hold part of regex, but part of what regex matched. So it will not hold `.` expression, but character which was matched by it at a time. Some flags like Pattern.CASE_INSENSITIVE - also represented as `(?i)` can allow backreference to describe match from that group in other forms like `fooFOO".matches("(?i)(...)\\1")` will return true (without that case insensitivity flag `\1` wouldn't accept `FOO` as string which also matches `foo` held by group 1). – Pshemo Sep 13 '17 at 18:08
  • 1
    Let's evaluate the regex: `(.)\1` used on the string `22`... First capture group is the character `2`. Since `\1` references the first capture group, `22` is matched. Evaluating the same regex `(.)\1` with `23`, we won't match it since `\1` references `2` and `3` != `2` – ctwheels Sep 13 '17 at 19:16

0 Answers0