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 reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
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.)
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
Related
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 reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Which of the following regular expressions can be used to get the domain name?
I try the next code but it doesn't work, there is something that i'm doing wrong?
In the picture the another options
txt = 'I refer to https://google.com and i never refer http://www.baidu.com'
print(txt.findall(?<=https:\/\/)([A-Za-z0-9.]*))
You selected the correct regexp, you just have to quote it to use it in Python. You also need to call re.findall(), it's not a string method.
import re
txt = 'I refer to https://google.com and i never refer http://www.baidu.com'
print(re.findall(r'(?<=https:\/\/)([A-Za-z0-9.]*)', txt))
Here's a regex that'll get your URLs
http(s?)://(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]
It'll work for https://stackoverflow.com, http://example.com, https://example.com etc...
If you don't want the http or https just use this:
(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a list of words, and a few definitions as follows:
word - trans1, trans2, trans3 ...
I'm now unsure if all those translations are correct. I want to use a library that for that given word gives all translations possible
word - trans1 ... transn
I'll then match each of my translations to those provided by the library / translation software, and make sure that it is a valid translation. The problem is I don't know of such a library. I do not want something like googletrans as it only provides one possible translation [because it is used to translating paragraphs] and there is a clear word / search limit every time I use it, stopping abruptly after a few with just running a few trials. It also is inconsistent in its translation pattern, for example sometimes adding "to" to the infinitives of verbs and sometimes not. Is there something like this that exists? Essentially what I want is a many result English-destinationlanguage dictionary library.
Google Translate API is probably your best bet out there. I'm no Google fanboy but credit where credit's due, and Google Translate is probably the best in the game right now.
As far as the problem of the program abruptly stopping, make sure that you're using the API correctly(read this).
As far as the infinitives are concerned, machines generally suck at translation, to understand watch this great video by Tom Scott.
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 reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am trying to code a RFID access system that utilizes an actuator to turn on and off. I followed a simple tutorial that can be found here.
I completed the tutorial fully and now have encountered problems:
I noticed when following the tutorial, the "python" we were coding was different from actual Python... for example, we don't do the curly brackets to end anything. Is there a way I can program and have access to my RFID module with the normal "Python" that I learned?
I am having issues finding the syntax's attached to SimpleMFRC522, because from what I read, it is a simplified way to interact with the RFID reader. So shouldn't there be certain syntax/functions attached to it?
When running a simple program that reads a tags ID and TEXT associated with the tag, I come across errors that usually wouldn't be an error on the normal python, for example...
Python Code
After running that code (labeled 'Python Code'), I come across...
Actual Error
I am extremely confused and need guidance or referral to anything I could possibly learn to help me finish this project. All or any help is appreciated and seriously considered.
Similar issue to this post.
You cannot concatenate a string and an integer so you must pull the id out of the object then typecast it to a string:
unsure what the 'id' name is within the object but let's assume it's 'id'
... (code above)
try:
print('Place your tag to be read.')
id_obj, text = reader.read()
print('Your ID is ' + str(id_obj.id))
print('Your text is ' + text)
... (code below)
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 reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have a regex that works fine on regex tester. Refer the below link:
https://regex101.com/r/4ogObc/4
But when I try to use it in python jupyter notebook, it does not match anything. This probably is because the tester has pcre(PHP) flavor.
Would be great if someone could help me fix this.
[[:punct:]] is a method in php, other programming languages do not support it. It's the reason that your regex doesn't work.
The following regex can work on python or Javascript:
([a-zA-Z\.\(\)\:\-\?\*\&\^\%\$\#\#\!\`\~\/\\\'\"\;\,\.\<\>]+(?:\s+[A-Za-z\.\(\)\:\-\?\*\&\^\%\$\#\#\!\`\~\/\\\'\"\;\,\.\<\>]+)*)(\s+[0-9]+\.[0-9]{2})
Python regex
But this regex is too long that I don't like it(Some too long regex will get time out),therefore, as you see, this regex takes about 581ms, and your regex takes about 423ms. Now your test string is not too long, when you match a greater webpages(a web crawl), it can take some time.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
this is for a school class i am learning computer scicence and i am working on a this code and i have been having some trouble and it is very hard to understand my teacher so i was wondering if anyone would be willing to help me with this program
gridl=[]
inputO=input("Please Enter").split(",") #Input Statement 1
numberO=inputO[0]#The Number Of "O" in the Input
Ocord=inputO[1:len(inputO)]#The O's
numberO=int(numberO)
for j in range(0,len(Ocord)):
gridl.append(Ocord[j-1:j+1])
for i in range(0:len(gridl))
newgrid=[]
inputX=input("Please Enter").split(",") #Input Statement 2
numberX=inputX[0] #The Number Of "X" in the Input
Xcord=inputX[1:len(inputX)]
print (Xcord)
The Rules and instructions:
Test inputs and outputs:
This is for an assignment, and you have done nothing except try (and fail) to get the first couple of lines read in. So I'm not going to be able to help you with your code - there's no code.
Instead, here are some hints:
Don't do things piecemeal if you can avoid it. When you're reading input, read all the input. When you're parsing the input, parse all the input.
You're going to make a bunch of mistakes doing this. It would help you to be able to "see" what you're doing. So, even though it's not required, I strongly suggest you make a function that will print out your game board. That way, you'll be able to "see" the situations of the pieces.
You're going to be doing some common operations, like adding pieces and getting the value of pieces. Make functions for those actions, if you can. Raise exceptions when things go wrong. The more time you spend being strict at the bottom levels, the less stupid mistakes you allow yourself to make at the top levels.
Get your types right. According to the instructions, everything in the input and output will be a number, except for the word 'None'. So you need to make sure that your input is all converted to numbers as soon as possible.