#🔒 how to create regex and use it in python?
46 messages · Page 1 of 1 (latest)
@vital terrace
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
here is the format of a casual text:
locator=MTE2[redacted]&retry=MA**&returncd=MDAx&token=vTG[redacted]
now this changes every time its requested
its basically like a better uptime robot im working on
not just a simple ping but see if i can get a response like that
i put redacted to hide sensitive information
but the locater= retry= returncd= and token= stays on every request
i found a regex generator would this work:
import re
def use_regex(input_text):
pattern = re.compile(r"locator=\*&retry=\*&returncd=\*&token=\*", re.IGNORECASE)
return pattern.match(input_text)
A tool to generate simple regular expressions from sample text. Enable less experienced developers to create regex smoothly.
oh wait nvm i did it wrong
now im gonna try the new one
ok funny how i got it working
import re
pattern = r"[A-Za-z]+.*&[A-Za-z]+.*&.*&[A-Za-z]+.*&[A-Za-z]+"
text = input("Enter text: ")
if re.search(pattern=pattern, string=text, flags=re.IGNORECASE): #type: ignore
print("yes")
else:
print('nope')
this is very plain but if anybody have something like this someday, here lol
@vital terrace you can use regex101 to confirm that your regex pattern works correctly for expected matches. https://regex101.com/
you can also use this to learn regex https://regexone.com/
RegexOne provides a set of interactive lessons and exercises to help you learn regular expressions
i already tested it
now i need help with this
you might not know whats wrong unless you know 3ds servers and stuff
one time I told someone to use regexone to learn regex, and he said cuss words to me.
but i keep getting null error code instead of it being successful
there is no "null error code" in Python. what was the whole error message?
it would help if you made an example that fully encapsulates the problem, without any [redacted] or calls to input.
using .* liberally can create problems, because it can match the entire rest of the string.
i fixed my regix
*regex
it works now i removed that already
its just interacting with servers
i put redacted because that is very sensitive info
(console unique info)
if i put it here anybody could use it and pretend they were me, cheat, and get me banned
I don't have enough information about the problem you are currently having to help you.
yeah thats what i was assuming
thanks for the regex thing though
you can close now
i solved my own problem lol
to be clear, no one does except you
yes lol
okay, you can !close the thread if you want.
if you want help with your current question, open a new thread and give the whole error message and the code.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.