#🔒 how to create regex and use it in python?

46 messages · Page 1 of 1 (latest)

vital terrace
#

im trying to make a regex that checks if its that, i know how to do if statements and compare but i want to know how to use re and check with regex, assuming its slightly different

uncut cipherBOT
#

@vital terrace

Python help channel opened

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.

vital terrace
#

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

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

zenith narwhal
#

@vital terrace you can use regex101 to confirm that your regex pattern works correctly for expected matches. https://regex101.com/

regex101

Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.

vital terrace
#

i already tested it

#

now i need help with this

#

you might not know whats wrong unless you know 3ds servers and stuff

zenith narwhal
#

one time I told someone to use regexone to learn regex, and he said cuss words to me.

vital terrace
#

but i keep getting null error code instead of it being successful

zenith narwhal
vital terrace
#

no im interacting with servers

#

that i think where you might not know

zenith narwhal
#

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.

vital terrace
#

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

zenith narwhal
#

I don't have enough information about the problem you are currently having to help you.

vital terrace
#

yeah thats what i was assuming

#

thanks for the regex thing though

#

you can close now

#

i solved my own problem lol

zenith narwhal
vital terrace
#

yes lol

zenith narwhal
#

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.

vital terrace
#

thanks

#

!close

uncut cipherBOT
#
Python help channel closed

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.