How to find and replace a particular character but only if it is in quotes?

后端 未结 6 2084
故里飘歌
故里飘歌 2021-02-19 01:29

Problem: I have thousands of documents which contains a specific character I don\'t want. E.g. the character a. These documents contain a variety of characters, but

6条回答
  •  悲&欢浪女
    2021-02-19 02:06

    "Inside double quotes" is rather tricky, because there are may complicating scenarios to consider to fully automate this.

    What are your precise rules for "enclosed by quotes"? Do you need to consider multi-line quotes? Do you have quoted strings containing escaped quotes or quotes used other than starting/ending string quotation?

    However there may be a fairly simple expression to do much of what you want.

    Search expression: ("[^a"]*)a

    Replacement expression: $1b

    This doesn't consider inside or outside of quotes - you have do that visually. But it highlights text from the quote to the matching character, so you can quickly decide if this is inside or not.

    If you can live with the visual inspection, then we can build up this pattern to include different quote types and upper and lower case.

提交回复
热议问题