Reputation: 181
I need use c# RegEx to process a string. The idea is delete initials characteres, like a substring.
Example string := "04|aH 800 A574a C.R.";
The result should be "H 800 A574a C.R.".
But the patron is variable, because the string can be "4|aProtestas populares" and the result should be "Protestas populares"
Summarizing, I need the substring after a "|x" ignoring what is before this expression.
Thanks...
PD: Sorry by my english :S
Upvotes: 4
Views: 139
Reputation: 11788
This Regex gives you desired result :
(\|)[a-zA-Z](?<wanted>[\s\S]+)$
Group named 'wanted' gives the after "|x".
Upvotes: 0
Reputation: 172478
var stringNew = Regex.Replace(stringOld, @"^.*?\|.", "");
This removes everything
^
.*?
|
.
Upvotes: 4
Reputation: 10361
If the string always has the pipe and one char after it, then what you want to keep, you can just use String.IndexOf()
. Using one string method would be much faster then using a RegEx Object.
string str = "04|aH 800 A574a C.R.";
int nIndex = str.IndexOf('|') + 2;
string substr = str.Substring(nIndex); // contains "H 800 A574a C.R."
Upvotes: 2