Can I substitute multiple items in a single regular expression in VIM or Perl?

后端 未结 7 1422
情歌与酒
情歌与酒 2020-12-02 15:57

Let\'s say I have string \"The quick brown fox jumps over the lazy dog\" can I change this to \"The slow brown fox jumps over the energetic dog\" with one regular expression

相关标签:
7条回答
  • 2020-12-02 16:36

    Chas's answer is good, the only other thing I'd mention is that if you're doing word swaps you probably want to be matching on

    \b(foo|bar|baz|qux)\b

    to avoid matching substrings. If you doing a lot of word swapping, you might start to find regexps a bit limiting and want to do something like:

    join '', map { exists $subst{$_} ? $subst{$_} : $_ } split /\b/, $string
    
    0 讨论(0)
提交回复
热议问题