Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I have following regular expression

private static readonly Regex TokenRegex = new Regex(
         "\\s*((?<string>\"(?:\"\"|[^\"])*\")|(?<union_ranges>[A-Z]+[0-9]+:[A-Z]+[0-9]+(\\s[A-Z]+[0-9]+:[A-Z]+[0-9]+)+)"
         + "|(?<range>\\$?[A-Z]+\\$?[0-9]*:\\$?[A-Z]+\\$?[0-9]*)"
         + "|(?<cell>\\$?[A-Z]+\\$?[0-9]+)"
         + "|(?<token>-)|(?<number>\\-?\\d*\\"
         + System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator + "?\\d+)"
         + "|(?<true>(?i)TRUE)|(?<false>(?i)FALSE)|(?<identifier>\\w+)"
         + "|(?<token>\\=\\=|\\<\\>|\\<\\=|\\>\\=|\\<\\>|\\=|\\!|[\\=\\.\\,\\+\\-\\*\\/\\%\\<\\>\\(\\)\\&\\^]))",
         RegexOptions.Compiled);


I am trying to match
Match var4 = TokenRegex.Match("HEX2DEC");
but it is not giving me correct value (HEX2)

What I have tried:

C#
private static readonly Regex TokenRegex = new Regex("[A-Z]*[0-9]?[A-Z0-9]*",
                 RegexOptions.Compiled

with above rule it give me correct value but I need to make first regular expression working
Posted
Updated 7-Sep-21 8:32am
Comments
Richard Deeming 7-Sep-21 10:26am    
Rather than pasting a cryptic regex which doesn't work and asking us to "fix" it based on a single example input/output, try providing a detailed explanation of what you are trying to match, along with multiple examples of input and expected output.

1 solution

I removed line
+ "|(?<cell>\\$?[A-Z]+\\$?[0-9]+)"

and it worked.
 
Share this answer
 
v2

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