Pattern for apostrophe inside quotes

后端 未结 2 821
無奈伤痛
無奈伤痛 2021-01-28 06:02

I am looking for a pattern that can find apostrophes that are inside single quotes. For example the text

Foo \'can\'t\' bar \'don\'t\'

I want to find and replace

2条回答
  •  半阙折子戏
    2021-01-28 06:28

    I believe you need to require "word" characters to appear before and after a ' symbol, and it can be done with a word boundary:

    \b'\b
    

    See the regex demo

    To only match the quote inside letters use

    (?<=\p{L})'(?=\p{L})
    (?<=[[:alpha:]])'(?=[[:alpha:]])
    (?U)(?<=\p{Alpha})'(?=\p{Alpha})  # Java, double the backslashes in the string literal
    

    Or ASCII only

    (?<=[a-zA-Z])'(?=[a-zA-Z])
    

提交回复
热议问题