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 96767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:52:35+00:00 2026-05-10T23:52:35+00:00

What would be the best way to do this. The input string is <133_3><135_3><116_2>The

  • 0

What would be the best way to do this.

The input string is

<133_3><135_3><116_2>The other system worked for about 1 month</116_2> got some good images <137_3>on it then it started doing the same thing as the first one</137_3> so then I quit using either camera now they are just sitting and collecting dust.</135_3></133_3> 

the expected output is

{'The other system worked for about 1 month got some good images on it then it started doing the same thing as the first one so then I quit \ using either camera now they are just sitting and collecting dust.':[133, 135],  'The other system worked for about 1 month': [116],  'on it then it started doing the same thing as the first one':[137]  } 

that seems like a recursive regexp search but I can’t figure out how exactly.

I can think of a tedious recursive function as of now, but have a feeling that there should be a better way.

Related question: Can regular expressions be used to match nested patterns?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T23:52:36+00:00Added an answer on May 10, 2026 at 11:52 pm

    Use expat or another XML parser; it’s more explicit than anything else, considering you’re dealing with XML data anyway.

    However, note that XML element names can’t start with a number as your example has them.

    Here’s a parser that will do what you need, although you’ll need to tweak it to combine duplicate elements into one dict key:

    from xml.parsers.expat import ParserCreate  open_elements = {} result_dict = {}  def start_element(name, attrs):     open_elements[name] = True  def end_element(name):     del open_elements[name]  def char_data(data):     for element in open_elements:         cur = result_dict.setdefault(element, '')         result_dict[element] = cur + data  if __name__ == '__main__':     p = ParserCreate()      p.StartElementHandler = start_element     p.EndElementHandler = end_element     p.CharacterDataHandler = char_data      p.Parse(u'<_133_3><_135_3><_116_2>The other system worked for about 1 month</_116_2> got some good images <_137_3>on it then it started doing the same thing as the first one</_137_3> so then I quit using either camera now they are just sitting and collecting dust.</_135_3></_133_3>', 1)      print result_dict 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been wondering what the best way to do this would be. I've got
In a single paged application, would this be the best way to bind and
What would be the best way to properly concatenate string with an url inside?
What would be the best way and more idiomatic to break a string into
What would be the best way to convert a 50-digit String to a BigInteger
I want to make a code snippet database web application. Would the best way
What would be the best way to version a rails application? We want to
What would be the best way in Python to parse out chunks of text
What would be the best way to detect newline return method in PHP. CR,
What would be the best way to handle lightweight crash recovery for my program?

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.