Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8431861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:58:14+00:00 2026-06-10T05:58:14+00:00

I am on Google App Engine with Python 2.7 and here is the code

  • 0

I am on Google App Engine with Python 2.7 and here is the code snippet:

# -*- coding: utf-8 -*-
KEYWORD = u"英語"
URL = u"http://www.google.com/"
content = u"和製英語(わせいえいご)とは、日本で作られた英語風の日本語語彙のことである。"
p=re.compile(u'('+ KEYWORD +u')(?!(([^<>]*?)>)|([^>]*?</a>))',re.UNICODE)
output=p.sub(u'<a href="'+ URL +'">\1</a>',content)

The regular expression and p.sub worked correctly but the backreference \1 wont work! The output of \1 is something like this: ន

I try to modify the code with encode('utf-8') but the result is the same:

p=re.compile(u'('+ KEYWORD +u')(?!(([^<>]*?)>)|([^>]*?</a>))'.encode('utf-8'),re.UNICODE)
output=p.sub(u'<a href="'+ URL +'">\1</a>'.encode('utf-8'),content.encode('utf-8'))

Can anyone told me what is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:58:16+00:00Added an answer on June 10, 2026 at 5:58 am

    Turn the string with \1 into a raw string by adding an r immediately before it:

    output=p.sub(u'<a href="'+ URL +r'">\1</a>',content)
    

    This prevents the 1 from being interpreted as a backreferenced 1. Proof:

    # -*- coding: utf-8 -*-
    import re
    KEYWORD = u"英語"
    URL = u"http://www.google.com/"
    content = u"和製英語(わせいえいご)とは、日本で作られた英語風の日本語語彙のことである。"
    p=re.compile(u'('+ KEYWORD +u')(?!(([^<>]*?)>)|([^>]*?</a>))',re.UNICODE)
    print p.sub(u'<a href="'+ URL +'">\1</a>',content)
    print p.sub(u'<a href="'+ URL +r'">\1</a>',content)
    

    prints

    和製<a href="http://www.google.com/"></a>(わせいえいご)とは、日本で作られた<a href="http://www.google.com/"></a>風の日本語語彙のことである。
    和製<a href="http://www.google.com/">英語</a>(わせいえいご)とは、日本で作られた<a href="http://www.google.com/">英語</a>風の日本語語彙のことである。
    

    Only the latter works (英語 is within the google link).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Appstats as documented here: http://code.google.com/appengine/docs/python/tools/appstats.html It works fine, but every request now
I'm trying to do the python tutorial here http://code.google.com/appengine/docs/python/gettingstarted/helloworld.html (I have python 2.5 installed)
Are there any guidelines to writing Google App Engine Python code that would work
I have some python code for Google App Engine that responds with the string
I'm running a java code for getting info from a google-app-engine web service (testeserjaum.appspot.com),
I have a user input form here: http://www.7bks.com/create (Google login required) When you first
I am using Google App Engine (python), I want my users to be able
I'm using Google App Engine python. I want to know what browser the user
I'm using Google App Engine (Python) and Chanel api. Is it possible to show
I want to have multiple pages in google-app engine (python 2.7) and the followoing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.