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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:11:12+00:00 2026-05-31T09:11:12+00:00

Lets say I have this variable myvar = 81 And I want to search

  • 0

Lets say I have this variable

myvar = "81"

And I want to search through the lines that has strings like this and get the word inside the quotations:

static public Register myReg1 = new Register("D4_STAT_1", 81);
static public Register myReg2 = new Register("D5_STAT_1", 819);

In this case if I want to find the “D4_STAT_1”, by searching for myvar in the file, I know how to read each line, but the problem for me is how to search for a variable and get exactly the word inside the quotations.

Thanks.

  • 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-31T09:11:13+00:00Added an answer on May 31, 2026 at 9:11 am
    >>> import re
    >>> s = '''
    ... static public Register myReg1 = new Register("D4_STAT_1", 81);
    ... static public Register myReg2 = new Register("D5_STAT_1", 819);
    ... '''
    >>> myvar = "81"
    >>> re.search('static public Register \w+ = new Register\("(\w+)", %s\);' % re.escape(str(myvar)), s).group(1)
    'D4_STAT_1'
    

    Depending on the circumstances (the input file), you can also use a simpler:

    >>> re.search('Register\("(\w+)", %s\);' % re.escape(str(myvar)), s).group(1)
    'D4_STAT_1'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a variable $var that has not been defined. Why don't
Possible Duplicate: How Do I Access This Variable? Lets say I have the code:
Lets say I have an int variable n = 8. On most machines this
Lets say I have a SP that has a SELECT statements as follows, SELECT
So lets say I have this global variable foo , which while my server
lets say i have this variable : ... Somekindofobject var = new Somekindofobject(); ...
Lets say i have something like this: This is file tree.py: class leaf(): def
Lets say I have a variable 'userid', I want to select from aspnet_Membership AND
Lets say I have this assignment : $(myObj).val('1') now lets say I want to
I have a convoluted search request. Lets say that I am searching for an

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.