1

I get job contents that contain many word that I want to 'remove/replace' from the content. Example:

postcodes,Thank you , Click here 

Problem

I have a list of words I want to remove from the content, but I am not sure how the words will appear within the content (upper case/lower case)...

So, how do I replace them?

Example - I want to replace:

associate degree in electronics or applicable equivalent

But in the content it can be :

associate Degree in electronics or applicable equivalent
Associate DEGREE in electronics or applicable equivalent
ASSOCIATE DEGREE IN ELECTRONICS or applicable equivalent

How can I replace them?

2 Answers 2

1

Try this:

(?i)(associate DEGREE in ELECtronics)
Sign up to request clarification or add additional context in comments.

11 Comments

Is it necessary to put | between the words?What if i have text like: hello & good morning friends!!!
@confusedMind, | is logical or. In other words this regex matches associate or degree or ...
Or , so suppose if i have in content associate degree in science , will it remove associate degree from this too as i do not want it?
@confusedMind, It will remove any word specified in regex. In this case: associate, degree and in.
Thank's a lot for the help! Really appreciated.
|
0

If you want to use Regex one possible solution will be:

Regex.Replace(input, @"(?i)(associate\s+degree\s+in\s+electronics\s+or\s+applicable\s+equivalent)", String.Empty);

You can use the same patter but create a Regex object, so you can provide a RegexOptions like:

Regex r = new Regex(@"(?i)(associate\s+degree\s+in\s+electronics\s+or\s+applicable\s+equivalent)", RegexOptions.Compiled);

and later on you can use it as:

r.Replace(input, String.Empty);

Note: using a concrete Regex object gives you advantage of more flexible Replacement strategies, like MatchEvaluator, number of replacements as a count, etc...

1 Comment

Thank you for posting the answer but i just got help a few mins ago :).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.