Regular expression to detect keywords ERP and C# and C++?

regex

#1

I want to detect several keywords as whole words within a string, through Regex pattern.
I started with the keyword ERP, by simply using the following pattern: \bERP\b
But this won’t work with the keyword C#, meaning that I’m unable to find C# using the pattern \bC#\b In the same way, I’m also unable to find \bC++\b as a whole word.
And \bERP\b doesn’t find the following string: ERP6
And I would like for it be detected.
Can someone help me out with a regular expression for detecting only whole words, and entering into account with the above mentioned issues?
Thanks in advance!


#2

Taking the following test string into account: https://regex101.com/r/pEsc5E/4 , I would like only the following keywords to be detected:

erp
ERP
c++
C#
C++
erp6

Only whole words. No substrings. Meaning that I don’t want “erp” to be detected within the word “PowerPoint”.


#3

Hi @jcab,

Pattern: ([Cc]\+\+)
Pattern: ([Cc]\#)
Pattern: ([EeRrPp])
Pattern: ([erp6])

Regards,
Arivu


#4

To find all the keywords in single regex pattern???

Regards,
Arivu


#5

Yes, to find everything in a single pattern.

This is related to the following topic: Regex expression to match a keyword within a string, delimited by spaces, comas and semicolons

I have an Excel file with a lot of keywords. These keywords may be for example: ERP, SQP, c++, c#.
The keywords are read from the Excel file into the variable “keyword”.
I then search the variable keyword in a given big string. And only whole words shall be matched. Meaning that “erp” shall not be matched in the string “PowerPoint”.

So initially i used the regex pattern “\b”+keyword+"\b". And it seemed to work good. But in the end it didn’t match c# or c++ or ERP6.
That’s the reason I’m trying to find some help to detect this in a single pattern :slight_smile:


#6

Hi @jcab,
Try this pattern
(([Cc]\+\+)|[EeRrPp][6]?|([Cc]\#))

Regards,
Arivu


#7

Sorry, it does not work.