#๐Ÿ”’ Regex issue

19 messages ยท Page 1 of 1 (latest)

raw solsticeBOT
#

@regal forge

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.

regal forge
#

I have a regex issue with my python code:
It ment to match ?i= it works on regex 101 but not python

import re

# Define the regex pattern
pattern = r'/(?<=\?i=)[^"\s]+/';

try:
    # Open the file and read its contents
    with open('test.txt', 'r') as file:
        content = file.read()

    # Find all matches
    matches = re.findall(pattern, content)

    # Print the matches
    print("Found matches:")
    for i, match in enumerate(matches, 1):
        print(f"Match {i}: {match}")

except FileNotFoundError:
    print("Error: The file 'test.txt' was not found.")
except IOError as e:
    print(f"Error reading the file: {e}")
except re.error as e:
    print(f"Regex error: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

https://paste.pythondiscord.com/6ZHQ

void mason
regal forge
#

How can I give you a link?

tough lichen
#

hey

#

got your issue

void mason
#

Save the regex101

#

Share the link

tough lichen
#

you're using the wrong regex

regal forge
tough lichen
#

it works on php regex

#

you need to use python regex

#

try this (?<=\?i=)[^\"\s]+

regal forge
#

Okay thankyou.

#

It's solved.

tough lichen
#

no problem

raw solsticeBOT
#
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.

#

๐Ÿ”’ Regex issue