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 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

i'm trying to find out if a string value EndsWith another string. This 'other
How can I receive a string value, find an Entity with the same name
Is string a value type or a reference type? I just can't find a
I want to find out the integer value associated to a string into the
I want to find the Xelement attribute.value which children have a concrete attribute.value. string
Why does javac add values() and valueOf(String) methods to the enum type being defined?
i want to find values in array according to alphabate and want to make
I am using the REGEXP_LIKE function in Oracle 10g to find values in a
I am trying to construct a Groovy statement to find values that don't exist
I would like to find the values of some of windows API constants, such

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.