What does $1, $2, etc. mean in Regular Expressions?

后端 未结 2 2194
一个人的身影
一个人的身影 2020-12-25 11:10

Time and time again I see $1 and $2 being used in code. What does it mean? Can you please include examples?

2条回答
  •  抹茶落季
    2020-12-25 11:32

    This is esp. useful for Replacement String Syntax (i.e. Format Strings) Goes good for Cases/Case Foldings for Find & Replaces. To reference a capture, use $n where n is the capture register number. Using $0 means the entire match. Example : Find: ()(.*?)() Replace: $1\u$2\e$3

提交回复
热议问题