Quote:
I have tried the following method which did not work for me.
It is a good idea to show examples of how it don't work.
Quote:
I have a .txt file with a bunch of sentences and a .txt file with words I want to remove from the first file.
Removing words is a little more complicated than what you did.
string pattern = @"\b"+removeW+"\b";
In a sentence, a word is not necessary embedded between spaces, you can have , . ? ! and nothing if the word is first or last in string.
Another problem is that when you remove a word, you don't want to remove both spaces around the word, you need to keep 1 space.
So replacing by a space will already an improvement:
string pattern = @"\b"+removeW+"\b";
string output = Regex.Replace(lines, pattern, " ");
You need to define what to do when a word is not between spaces, then deduce how it translate into code.
-----
Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[
^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[
^]
Expresso Regular Expression Tool[
^]
RegExr: Learn, Build, & Test RegEx[
^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[
^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[
^]
This site also show the Regex in a nice graph but can't test what match the RegEx:
Regexper[
^]