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

I have following regular expression

private static readonly Regex TokenRegex = new Regex(
         + "|(?<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>\\=\\=|\\<\\>|\\<\\=|\\>\\=|\\<\\>|\\=|\\!|[\\=\\.\\,\\+\\-\\*\\/\\%\\<\\>\\(\\)\\&\\^]))",

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

What I have tried:

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

with above rule it give me correct value but I need to make first regular expression working
Updated 7-Sep-21 9:32am
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.

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