#๐ Confused
38 messages ยท Page 1 of 1 (latest)
@bleak hemlock
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.
Any idea on what went wrong here?
\u, which you have in that string, is a special escape character, similar to \n. It expects a number after the u to indicate a Unicode character of a specific code.
If you want \ literally in the string, you need to either escape them by changing them all to \\, or by making the string they're in a raw string by prefixing the string with an r: r'<\u>'.
i am still a bit confused
i get what the error is
but wdym by prefixing the string
Look at the example I gave at the end. Note the r before the opening ' quote.
but wouldn't that register in python as regex
r'This is a raw string'
No. r means raw. It's just sometimes used when creating regexes because regexes can contain backslashes.
It will have an effect.
Making it a raw string will fix the current error.
oh
i always use r
before inputting a regex pattern into python
so that's why my mind was confused when you suggested that
Ah. They're unrelated ideas that both just happen to start with R.
Just to clarify a bit: the r isn't for "regexp", it's for "raw". We use raw strings for both regexps and Windows paths-containing-backslashes to avoid Python interpreting the backslashes itself, instead passing them through into the string unchanged for use by whatever wants the (the regexp or windows path).
Thanks, that does help a lot.
the pattern should probably be r"</?[A-Za-z]+>" as the optional / should be the first character within the angled brackets and ? is not a valid character within a tag name
within the square brackets in a regex most characters are without special meaning (there are some exceptions though)
let me check what mine turned out to be
but it worked
so that's why i kept it
it may seem like it works as it should at first glance, but your version will also accept tags that aren't valid tags in this string "<d/iv> <di?v>" and so on
i don't think that this is something you want, right?
oh ok fair enough
i will fix it then
Thanks
you're welcome
you understand why this is and how this problem came about?
yes
thanks
it's from mistakes you learn the most
This help channel has been closed. 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.