0

I am working with Regex that does not match properly:

Regex.Match("\u0002\u0002BURDETTE\u0002ST\u0002\u0002\u00022115\u0004^CONESTOGA MAGNET ELEM SCH^^^ ", @"\u0002([\w\s\u0000\u0001\u0002\u0003\u0004/.,:&-]+)^([\w\s^/.,:&-]+)")

I have no problems matching separate parts of regex:

Regex.Match("\u0002\u0002BURDETTE\u0002ST\u0002\u0002\u00022115\u0004^CONESTOGA MAGNET ELEM SCH^^^ ", @"\u0002([\w\s\u0000\u0001\u0002\u0003\u0004/.,:&-]+)")  

Matches: {BURDETTEST2115}

Regex.Match("^CONESTOGA MAGNET ELEM SCH^^^ ", @"^([\w\s^/.,:&-]+)")

Matches:{^CONESTOGA MAGNET ELEM SCH^^^ }

newprint
  • 6,936
  • 13
  • 67
  • 109
  • 2
    Well no, because `^` has special meaning in regular expressions... See https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx#atomic_zerowidth_assertions If you want to match the actual `^` symbol, you need to escape it... – Jon Skeet May 24 '17 at 19:48
  • 1
    See http://ideone.com/fBvw4u – Wiktor Stribiżew May 24 '17 at 19:49
  • 1
    On the regex, `^` is a metacharacter meaning beginning of string. To make it literal it has to be escaped => `\^` –  May 24 '17 at 19:56

0 Answers0