regex - What's regexp `^\(.*\)\n\1$` mean? -
i happen find regular expression in sed
documents:
^\(.*\)\n\1$
and explains:
matches string consisting of 2 equal substrings separated newline.
i can see matches characters, ends newline, nothing more. give me explanation?
the patterns inside parentheses ()
called capture groups.
the \1
means "whatever matched first capture group".
here's character character breakdown:
^ - matches beginning of input \( - begin capture group (the `(` character must escaped backslash) .* - 0 or more characters \) - end capture group \n - newline character \1 - text "captured" first capture group $ - matches end of input
Comments
Post a Comment