0

I got bbcodepy and I'm allowed to modify it, but I can't import it in my main.py. I keep getting a SyntaxError and I don't really know what's wrong with the code because I didn't write it. I just want to tinker around a little bit and see if I can get it to fill my needs. Here's an image pointing me in the direction of the syntax error. But I noticed the same code is written on the same line and I don't get the SyntaxError for that. Here's the code:

_URL_RE = re.compile(ur'''\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&amp;|&quot;)*(?:[^!"#$%&'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&amp;|&quot;)*\)))+)''')

The problem appears to be "[^\s&()]" but only the second one, not the first one. If you look closely in the code you'll see that the same thing appears twice, but I only get the SyntaxError on the second appearance. Someone enlighten me, please. I've been trying to find a decent BBCode parser for Python for a couple of days now and I believe this is the one I can modify to my needs. I can't seem to get bbcode to work as I want it to, so I'm trying this out.

1 Answer 1

0

Well, Python version 3.4 and above does not support a 'UR' prefix.

You need to execute your code with Python 2.7, or change to line into:

_URL_RE = re.compile(r'''\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&amp;|&quot;)*(?:[^!"#$%&'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&amp;|&quot;)*\)))+)''')

See also: python version 3.4 does not support a 'ur' prefix

Note: consider avoiding triple-quoted string because if you insert a newline, it can change the meaning of the regex (unless it is compiled in VERBOSE mode).

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

2 Comments

@DomniusCarswell, you are welcome. You can upvote/accept this answer: stackoverflow.com/help/someone-answers
There's a 5 minute wait until I can accept the answer, I sure will. Don't worry

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.