1

How can I replace these trailing "N megapixels" strings with "" using Regular Expression (RegEx.Replace)?

Examples:

If we enter: "Powershot Yellow 12.1 Megapixels", the result would be: "Powershot Yellow"

if we enter: "Powershot Black II 10 Megapixels", the result would be: "Powershot Black II"

skaffman
  • 398,947
  • 96
  • 818
  • 769
Junior Mayhé
  • 16,144
  • 26
  • 115
  • 161

3 Answers3

3

How about something simple like...

var newStr = Regex.Replace(input, @"\s+[\d\.]+\s*Megapixels", "", RegexOptions.IgnoreCase);
Andrew White
  • 52,720
  • 19
  • 113
  • 137
0

Try this:

var newString = Regex.Replace(candidate, @"\d+\.?\d+ Megapixels", "");
Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
0
var camera = Regex.Replace(input, @"\s+[.\d]+\s+Megapixels", "", RegexOptions.IgnoreCase);
agent-j
  • 27,335
  • 5
  • 52
  • 79