Mikkel Finnerup Andreasen Mikkel Finnerup Andreasen - 6 months ago 31
C# Question

Regex to extract multiple different words from a string

I am looking for a regex that gives me something of the format:

"Core i7 Extreme Edition" or "Core i3" or "Atom" or "Pentium", given the following inputs:

"Intel® Core™ i7-6950X Processor Extreme Edition", "Intel® Core™ i3-6300T Processor", "Intel® Atom™ Processor D2550 " or "Intel® Pentium® Processor G4400" or "Intel® Core™2 Duo Processor E6400" or "Intel® Core™2 Extreme Processor QX6800" or "Intel® Core™2 Quad Processor Q9400S".

I want to read the special identifying features from the product name.

I realise that something along the lines of this:
Core|i3|i5|i7|Atom|Pentium|\s4\s|Celeron|Extreme Edition

Will give me what I want in a perfect world, where nothing is added.

It is possible to create it?
If it adds anything I am using C# but it is in an environment that is very generic and I only have the string and the regex.


You can try this regex: (See on regex101)

Intel® | Processor|®|™|[ -][A-Z]*\d{4}[A-Z]*

And replace with empty string "". This matches all non-wanted parts and removes them.

string pattern = @"Intel® | Processor|®|™|[ -][A-Z]*\d{4}[A-Z]*";
string substitution = @"";
string input = @"Intel® Core™ i7-6950X Processor Extreme Edition";
Regex regex = new Regex(pattern);
string result = regex.Replace(input, substitution);