0

I have this regex: If you don't want these messages, please [a-zA-Z0-9öäüÖÄÜ<>\n\-=#;&?_ "/:.@]+settings<\/a>. It works on regexr but not when I am using the re library in Python:

data = "<my text (comes from a file)>"
search = "If you don't want these messages, please [a-zA-Z0-9öäüÖÄÜ<>\n\-=#;&?_ \"/:.@]+settings<\/a>" # this search string comes from a database, so it's not hardcoded into my script
print(re.search(search, data))

Is there something I don't see?

3
  • 3
    Maybe add r in front of string and copy paste from regexr? r"abcd\rawstring" Commented Dec 18, 2022 at 11:30
  • 3
    Besides what @jupiterbjy just pointed out, you should add some test data if you want any further help. :) Commented Dec 18, 2022 at 11:32
  • Just put the hitherto escaped hyphen in the first or last position of the class where it can't constitute a range: [a-z...\\- to [-a-z.... No need to escape it there. Commented Dec 18, 2022 at 14:24

1 Answer 1

1

the pattern you are using on regexr contains \- but in your exemple shows \\- wich may give an incorrect regex. (and add the r in front of of the string as jupiterby said).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.