Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Input:"1-1,2-2,2-3,3-2,4-1...."
Expected output:1,2,3,2,1
need to remove 1- 2- 3- 4- characters please help

What I have tried:

string Testdata = "1-1,2-1,2-2";
string input = Regex.Replace(Testdata, @"(\s+|-|'|#)", "");
its not wotking
op:11,21,22
Posted
Updated 21-Jan-18 23:29pm
Comments
phil.o 22-Jan-18 5:27am    
Would you care explaining the one-vote?

string Testdata = "1-1,2-2,2-3,3-2,4-1..";
string input = Regex.Replace(Testdata, @"(-\d+)", "");
 
Share this answer
 
The regular expression for what you are interested in is [\d]+- (formally, any sequence of at least one digit followed by a minus sign).
C#
string input = Regex.Replace(Testdata, @"[\d]+-", "");

You could also search for "Expresso regular expression" and download this free software which will help you building meaningful regular expressions.
Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900