How can I get a regex to match whole words like grand and not match mygrandma

how can I get a regex to match whole words like grand and not match mygrandma.

for example, I want to replace "grand" with "total",

so the "grand sum of 100" should become the "total of 100".

however, "My grandmother loves apples" should not become "my total likes apples."

+3
source share
1 answer

\b. , , , :

// Verbatim string
@"\bgrand\b"

// Normal string
"\\bgrand\\b"
+4

Source: https://habr.com/ru/post/1761420/


All Articles