Using regex to ignore invalid syntax [closed]

2024/11/15 17:50:40

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

Answer

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

https://en.xdnf.cn/q/120423.html

Related Q&A

What is the requirements.txt file? What should be in it in this particular case?

I am switching from Replit to PebbleHost to host my Python bot. What do I put in my requirements.txt file? These are the imports that I have at the start of my bot. import asyncio import datetime impo…

Is this a linux or a virtualenv error?

I asked this question 4 days ago.Now, when I open a terminal, I see this:and this:Is it related to the initial problem i had, or it a python and virtualenv issue?

Python code to authenticate to website, navigate through links and download files

Im looking something which could be interesting to you as well. Im developing a feature using Python, which should be able to authenticate (using userid/password and/or with other preferred authentica…

How to get sum of products of all combinations in an array in Python? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

How to get value from entry (Tkinter), use it in formula and print the result it in label

When using the function entry of Tkinter, you can write a string value and do things with it; but Im actually working with formulas. The idea is fairly simple: to put a bunch of boxes to fill with numb…

Printing tuples in a list

Im not getting how to proceed with this problem in lists,can any one help me out? Thanks in advance.input is :l = [(1,2),(3,4),(5,6)]output is:[(1,3,5),(2,4,6)]

Adding entries from multiple files in python

I have a question on how to add entries from 100 files (each file contains two columns) and then writing them to a new file(which will also contain two columns)?

Multiply list in list string items with list in list integers

I have 2 lists: list1 and list2 list1 is a list in list and contains various strings list2 is also a list in list and consists of different integer values the dimensions of both lists is the same how d…

I want to complete the quiz with variables or lists without Python input

import random number = random.randint(1, 10)player_name = input("Hello, Whats your name?") number_of_guesses = 0 print(okay! + player_name+ I am Guessing a number between 1 and 10:)while nu…

Comparing a list to a a list of tuples?

I have two lists. One is simply a list of idsids = [123, 124, 127, 316, 463]and the other is a list of tuples of ids and namescombined = [(123, "Brian"), (124,"Eric"), (222,"Ja…