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

  • SEARCH
  • Home
  • 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 8774681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:37:45+00:00 2026-06-13T18:37:45+00:00

[EDIT]: I Understand that regular expression are not made to parse XML, but my

  • 0

[EDIT]:

I Understand that regular expression are not made to parse XML, but my question is about WHY THAT REGULAR EXPRESSION DOESN’T COMPILE IN PYTHON.

I’m expecting answers about WHAT DOSN’T WORK in that regular expression and NOT WHY IT IS NOT A GOOD IDEA TO USE IT (and I don’t understand the down votes).

[/EDIT]

I’m trying to write a function that escapes the contend of an XML tag according to this document and I think that the best solution is to escape all the “<” and “&” that are not in a CDATA section.

I have a basic knowledge of regular expressions, so I looked around and I found this page and this one.

So apparently the regular expression that works with the “&” is:

&(?!(?:[a-zA-Z][a-zA-Z0-9]*|#\d+);)(?!(?>(?:(?!<!\[CDATA\[|\]\]>).)*)\]\]>)

but it doesn’t work in python, in fact if I try to use it I have:

In [1]: import re

In [2]: x = re.compile('&(?!(?:[a-zA-Z][a-zA-Z0-9]*|#\d+);)(?!(?>(?:(?!<!\[CDATA\[|\]\]>).)*)\]\]>)')
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-2-2884ec1d2f4e> in <module>()
----> 1 x = re.compile('&(?!(?:[a-zA-Z][a-zA-Z0-9]*|#\d+);)(?!(?>(?:(?!<!\[CDATA\[|\]\]>).)*)\]\]>)')

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/re.pyc in compile(pattern, flags)
    188 def compile(pattern, flags=0):
    189     "Compile a regular expression pattern, returning a pattern object."
--> 190     return _compile(pattern, flags)
    191 
    192 def purge():

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/re.pyc in _compile(*key)
    243         p = sre_compile.compile(pattern, flags)
    244     except error, v:
--> 245         raise error, v # invalid expression
    246     if len(_cache) >= _MAXCACHE:
    247         _cache.clear()

error: unexpected end of pattern

and this make me think that that regular expression is not written for python.

Any help?

  • 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-13T18:37:47+00:00Added an answer on June 13, 2026 at 6:37 pm

    Your regular expression fails to compile because the (?> ...) syntax for atomic grouping (aka “independent subexpressions”) is not supported by Python’s re module. There is an experimental reimplementation of re available on PyPI that does support atomic groups and other nice features, so you could try that instead.

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

Sidebar

Related Questions

Edit: To be clear, please understand that I am not using Regex to parse
*edit: I understand that stackoverflow has banned all questions regarding using Microsoft's Visio. I'm
this is an edit of the original post now that I better understand the
Edit (updated question) I have a simple C program: // it is not important
I have a very basic regular expression that I just can't figure out why
I have multiple line string that I'd like to replace, but don't understand why
I'm not sure how to accomplish this with a regular expression (or if I
edit - the question was not properly researched. The problem turned out to be
I'm not a ruby expert and may be this will seem a silly question...but
I've been trying to read about and test various regular expression testers to find

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.