-3

https://regex101.com/r/jK9mH3/1 That's the link to my regex, in order to not take up all the page i put it there, im trying to make it output a0, then a-z then aa-aq.

EDIT: Ok that was terrible im sorry, i need to run a program which checks the variable names of all dictionaries, but it wont be basic, i need it to check all different types of syntax like the ones listed in the checker, so it needs to be able to recognize that d = "{}" isnt actually a dictionary that its a string and that #z = {} is a comment not a dictionary. The output on the website will be a0, then a-z with no random z's in-between and then aa-aq (that is, aa, ab, ac, ad etc.)

3
  • 1
    Please describe what you want to detect! All variable names in front of =? Or something else? Commented Aug 13, 2015 at 2:21
  • 1
    What are you're trying to accomplish? Why ignore invalid syntax? Commented Aug 13, 2015 at 2:22
  • 2
    in theory that's not possible. regular expression is less powerful than context free grammar. Commented Aug 13, 2015 at 2:45

1 Answer 1

2

Although your question doesn't make a lot of sense, I believe that you're trying to detect valid python syntax in a given string.

Do NOT use regular expression for this. Use a lexer/parser for this. It's designed to handle the complex structures found in a language like python.

Guide to Lexing and Parsing

Sign up to request clarification or add additional context in comments.

1 Comment

i have to use something like that, sorry i was in a rush. I mean i need to get the variable names for all the dictionaries. So if it was d = "{ }" it wouldnt print d because that isnt a dictionary but if it was d ={}; e = {} it would print both d and e because they are valid.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.