-1

I Have an input text :

string DefaultInput = "Name : John | FamilyName : Doe |";

I Want to be able to Extract the "John" & "Doe" and maybe other values from 1 input using Regex

My Code :

Match m = Regex.Match(DefaultInput,"Name : (.*?) | FamilyName : (.*?) |");
this.textBox1.Text = "ProfileName : " + m.Groups[1].Value + "\r\nProfileFamilyName : " + m.Groups[2].Value;
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
MdSalehGh
  • 41
  • 1
  • 8

1 Answers1

0

You just need to escape regex alternative character | with \, because it is a part of its syntax:

Match m = Regex.Match(DefaultInput, "Name : (.*?) \\| FamilyName : (.*?) \\|");

and the code works.