RegExp regular expression find & replace whole words only

后端 未结 1 2022
执念已碎
执念已碎 2021-01-12 15:45

I should preface this by stating that I\'m working with VB6 & RegExp

I\'m attempting to find and substitute whole words, by \"whole words\" I mean a valid match

1条回答
  •  一整个雨季
    2021-01-12 16:05

    Use the "word boundary" expression \b.

    Perhaps something as simple as this will do:

    (.*)\bFoo\b(.*)
    

    FYI, the word boundary expression \b is a zero-width match between a word character \w and a non-word character [^\w] or visa versa, and consumes no input.


    Underscore and digit characters are considered "word characters", so Foo_Bar, Bar_Foo, and Foo123 wouldn't match. To rectify that, so that any non-letter is considered "end of word" (including start and end of input), use look arounds:

    (?i)(.*(?

    0 讨论(0)
提交回复
热议问题