Using regex to ignore invalid syntax [closed]

2019-09-21 17:37发布

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.)

标签: python regex
1条回答
一夜七次
2楼-- · 2019-09-21 18:09

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

查看更多
登录 后发表回答