[英]Regex - Replace only if the pattern is not inside a quote
假設我想寫一個正則表達式來用單詞Cat
替換單詞Dog
。
例如
Dogs are scary.
會變成:
Cats are scary.
但我希望只有在單詞 Dog 不在引號內時才應用此正則表達式。
例如
Dogs are scary but my mom told me that "Dogs are cute"
會變成:
Cats are scary but my mom told me that "Dogs are cute"
我不知道該怎么做。 請幫幫我 :)
對於更完整的功能,如果您需要變量來控制替換,請參閱https://stackoverflow.com/a/69428257/1432181了解類似問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.