Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re module does not handle backreferences in replacement text. #224

Open
pyjsorg opened this issue Apr 27, 2012 · 2 comments
Open

re module does not handle backreferences in replacement text. #224

pyjsorg opened this issue Apr 27, 2012 · 2 comments
Labels

Comments

@pyjsorg
Copy link
Contributor

pyjsorg commented Apr 27, 2012

The re module for pyjs does not handle backreferences in replacement
text.

For example, regexes to do simple reformatting of text, as in:

Text between single asterisks will be emphasized.
Text between double asterisks will be bolded.

Can be handled by these compiled regular expressions:

B_re = re.compile(r'\*\*(.*?)\*\*', re.DOTALL)
EM_re = re.compile(r'\*(.*?)\*', re.DOTALL)

and later used like this:

txt = myTextArea.getText()
txt = B_re.sub(r'<STRONG>\1</STRONG>', txt)
txt = EM_re.sub(r'<EM>\1</EM>', txt)

This works great with pyjd, but with pyjs, you get "\1" in the
replacement text, not the backreference.

Full example is attached.

Original issue: http://code.google.com/p/pyjamas/issues/detail?id=495 (September 18, 2010 16:02:23)

@chozabu
Copy link

chozabu commented Jul 3, 2013

Blast - just encountered this myself.

@chozabu
Copy link

chozabu commented Jul 3, 2013

my workaround is along these lines:

    otext = "text with a http://chozabu.org link"
    newtext=""+otext
    exp= r"((https?|ftp)://[^ ]+)"
    linklist=re.findall(exp, otext)

    for link in linklist:
        newlink = "<a href="+link[0]+">"+link[0]+"</a>"
        newtext = newtext.replace(link[0], newlink)
    self.add(HTML(newtext))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants