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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:25:18+00:00 2026-05-19T22:25:18+00:00

How to find values in string, add specific value to each of them and

  • 0

How to find values in string, add specific value to each of them and replace output with fixed string.

import re
def _replace(content):
    #x = float(content.group(4))+20
    #y = float(content.group(6))+20
    return content.group(6)
print re.sub('<g(\s)transform="matrix\((.*)(\s)(.*)(\s)(.*)\)\"', _replace, '<g transform="matrix(0.412445 -0.0982513 0.0982513 0.412445 -5.77618 67.0025)">')
  • 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-19T22:25:19+00:00Added an answer on May 19, 2026 at 10:25 pm

    First off, I should repeat the usual warning about not parsing XML with regexes. It’s a bad idea, and it will never work for all cases. If you’re actually trying to parse the full xml document, use an XML parser.

    That having been said, I’m guilty of doing quick and dirty stuff like this all the time. If you really just need a one-off solution, a simple regex can often get the job done. Just be aware that it will come back to haunt you as soon as you run into something more complex!

    Next, I confess to not being much of a regex wiz, but here’s how I’d modify your code snippet:

    import re
    
    def _replace(content):
        values = [float(val) for val in content.group(2).split()]
        values[3] += 20
        values[5] += 100
        values = ['{0}'.format(val) for val in values]
        return content.group(1) + ' '.join(values) + content.group(3)
    
    test_string = '<g transform="matrix(0.412445 -0.0982513 0.0982513 0.412445 -5.77618 67.0025)">'
    pattern = r'(transform=\"matrix\()(.*?)(\))'
    print test_string
    print re.sub(pattern, _replace, test_string)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What tool or method do you recommend to find and replace values in your
I want to parse some HTML in order to find the values of some
I often find myself using Integers to represent values in different spaces. For example...
I can't find a way to read resource values in a controller
Is there a way to find the maximum and minimum defined values of an
I have some function to find a value: struct FindPredicate { FindPredicate(const SomeType& t)
How can I find out which column and value is violating the constraint? The
I hope to find a way to get the value in the Nth column
What is the simplest SQL query to find the second largest integer value in
What's the best algorithm to find the smallest non zero positive value from 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.