How to isolate keyword in a search. Search for and count keywords in a string

I am performing a keyword search on a text file and returning all the sentences and count of keywords in the sentence. That part is not a problem. My problem is with searching for and counting only the keyword.

For example, “and” which comes in the form " and “, " and.”, " and/", and probably more, but not “ampersand”, “operand”, “Anderson”.

So far I have been counting all of the words “and”, and the words containing “and”.

The activity I’ve been using is

Assign:
count = System.Text.RegularExpressions.Regex.Matches(string,(“(?:and)”), System.Text.RegularExpressions.RegexOptions.IgnoreCase).Count

Hi,

How about the following expression?

count = System.Text.RegularExpressions.Regex.Matches(string,("\band\b"),System.Text.RegularExpressions.RegexOptions.IgnoreCase).Count

This will also match “and/” etc. does it fit for you?

Regards,

That worked wonderfully. Thank you.

I have some questions now.

What exactly did “\b” do?

Where can I learn about “\b” and related delimiters?

What would I search for to find help on such a topic?

Thanks again.

Hi,

The following document helps you. (See \b at Anchors section)

Regards,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.