Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have the following input string:
+20A, 100A, E+40, 100+, RK100H

I would like to extract the output below from the input:
+20A, E+40, 100+

My current function is only outputting E+20 string but not the +20A string.
C#
foreach (var match in Regex.Matches(list, @"[a-zA-z]+\+\d+"))
                                 {
                                     // Output each match here
                                     string b = "";
                                     b += match.ToString();
                                     row["Spre"] = b;
                                     row["Spre Value"] = value;
                                     row[6] = x;
                                 }


Is there something I am missing from my expression? Thanks
Posted

1 solution

Try this: (\+\d+[a-zA-Z])|(.\+\d+)|(\d+\+)
 
Share this answer
 
v2
Comments
miss786 28-May-15 7:15am    
Thank you for your response and help. However, when executing the above expression i get the following error parsing "(+|[a-zA-z])\d+(+|[a-zA-z])" - Quantifier {x,y} following nothing.. I have tried editing this but I cannot seem to resolve it. Thank you
Maciej Los 28-May-15 7:24am    
See updated solution ;)
Do not forget to add ExplicitCapture option!
miss786 28-May-15 7:45am    
Thank you you so much for the updated answer. I very much appreciated that. :)
Maciej Los 28-May-15 7:51am    
You're very welcome ;)
Sergey Alexandrovich Kryukov 28-May-15 11:41am    
The inquirer were missing it :-), a 5.
—SA

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