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

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -