具体来说,如果可能的话,我想将许多单词包装在自己的引号中。我知道之前已经有人问过这个问题,但坦白说,由于我不是N ++的编码人员或常规用户,所以我不明白答案。因此,如果可以像我2岁那样来解释它,那将不胜感激。
答案 0 :(得分:1)
(?<!")\b\w+\b(?!")
"$0"
说明:
(?<!") # negative lookbehind, make sure we haven't quote before the word
\b # word boundary
\w+ # 1 or more word character
\b # word boundary
(?!") # negative lookahead, make sure we haven't quote after the word
替换:
" # a double quote
$0 # the whole match (i.e. the word)
" # a double quote
给出:
Tony, Paul, Eric, Sarah, "Tony", "Paul", "Eric", "Sarah"
给定示例的结果
"Tony", "Paul", "Eric", "Sarah", "Tony", "Paul", "Eric", "Sarah"