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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:53:17+00:00 2026-05-19T00:53:17+00:00

I haven’t found my answer after reading through all of these posts, so I’m

  • 0

I haven’t found my answer after reading through all of these posts, so I’m hoping one of you heavy hitter regex folks can help me out. I’m trying to isolate the tag name and any attributes from the following string format:

{TAG:TYPE attr1="foo" attr2="bar" attr3="zing" attr4="zang" attr5="zoom" ...}

NOTE: in the above example, TAG will always be the same and TYPE will be one of several preset strings (e.g. share,print,display etc…). TAG and TYPE are uppercased only for the example but will not be case sensitive for real.

  • 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-05-19T00:53:18+00:00Added an answer on May 19, 2026 at 12:53 am

    For the moment, let’s assume that your attribute names and values, as well as your TAG and TYPE, are strictly alphanumeric. Parsing gets messier (and may not even be regular) if you could have ” or = inside those strings.

    With those caveats, here’s a python regex that gets the job done:

    >>> parse_regex=r'\{(?P<tag>\w+):(?P<type>\w+)(?P<attrs>(\s+\w+=\"\w+\")*)\}'
    >>> m = re.match(parse_regex, str)
    >>> m.group('tag')
    'TAG'
    >>> m.group('type')
    'TYPE'
    >>> m.group('attrs')
    ' attr1="foo" attr2="bar" attr3="zing" attr4="zang" attr5="zoom"'
    

    At this point, you’d want to clean up the attributes into a friendly data structure. Since there could be arbitrarily many of them, it’s going to be more convenient (and just as efficient) not to use regexps for this stage.

    >>> [attr_str.split('=') for attr_str in m.group('attrs').split()]
    [['attr1', '"foo"'], ['attr2', '"bar"'], ['attr3', '"zing"'], ['attr4', '"zang"'], ['attr5', '"zoom"']]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually haven't found the answer for this one. What for and why do i
Haven't found what i'm looking for so far. I want to redirect all my
Haven't fired up reflector to look at the difference but would one expect to
Haven't seen anything about it here but it seems to solve one of the
I haven't found anything about it on the web, does mono support ASP.NET 1.1
I haven't found any documentation on this or seen this done before, but is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I haven't found a way to detect if user is currently viewing a page,
Haven't found this in my search on Stackoverflow - I know I've seen a

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.