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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:47:51+00:00 2026-06-11T02:47:51+00:00

Can anyone tell me why the regex pattern in Python works most of the

  • 0

Can anyone tell me why the regex pattern in Python works most of the time but have difficulty with the following text.

PATTERN:

patternd = re.compile(r"""\(VFSCAN\)[^=]*=\s*    # first line of a section: (VFSCAN) AT TIME =  1.1800 UP    TO  100 BUSES WITH LOW VOLTAGE DEVIATION BELOW -0.200 
(\d*(?:\.\d+)?)                 # group 1 - first number of first line: 1.1800
\D+ 
\d+                             # second number of first line: 100 
\s+BUSES\s+WITH\s+LOW\s+VOLTAGE\s+(DEVIATION)\s+BELOW.*? 
\D+                             # skip second line 
(?:                             # a data line: 18436 [LENZIE 618.0] -0.245 18433 [LENZIE 318.0] -0.245
(?:\d+\s+\[(.+?)\]\s+\S+\s*)+   # Component of data line
(?=[\r\n\s]+|$) 
)+                              # This search ends with an empty line
""", re.VERBOSE)

The text I am having problems with is:

test3 = r'''(VFSCAN) AT TIME =  1.1800 UP TO  100 BUSES WITH LOW VOLTAGE DEVIATION BELOW -0.200:

X ----- BUS ------ X    VDEV       X ----- BUS ------ X    VDEV
18436 [LENZIE 618.0]   -0.245      18433 [LENZIE 318.0]   -0.245     
18431 [LENZIE 118.0]   -0.214      18435 [LENZIE 518.0]   -0.214     
18434 [LENZIE 418.0]   -0.214      18432 [LENZIE 218.0]   -0.214     

(VFSCAN) AT TIME =  1.5167 UP TO  100 BUSES WITH LOW VOLTAGE DEVIATION BELOW -0.200:

X ----- BUS ------ X    VDEV       X ----- BUS ------ X    VDEV
69036 [DNLP2G21.575]   -0.414      69038 [DNLP2G22.575]   -0.414     
69040 [DNLP2G23.575]   -0.414      69032 [DNLP1_G1.575]   -0.402     
65460 [DIFICULT 230]   -0.384      69027 [7MIHL G1.575]   -0.355     
69076 [HORIZ_G .575]   -0.303      67237 [MEDBOWCO 115]   -0.301     
67940 [STNDPSVC 230]   -0.300      65976 [MINERS  34.5]   -0.294     
65585 [FT CRK1 34.5]   -0.261      65584 [FT CRK2 34.5]   -0.261     
69073 [HIPLN_G .575]   -0.214     

(VFSCAN) AT TIME =  1.1800 UP TO  100 BUSES WITH LOW VOLTAGE DEVIATION BELOW -0.200:

X ----- BUS ------ X    VDEV       X ----- BUS ------ X    VDEV
65191 [BONANZA 24.0]   -0.572      65192 [BONANZA  138]   -0.434     
65194 [CHAPITA  138]   -0.433      66278 [RANGELY  138]   -0.320     
65371 [COVE TP  138]   -0.302      79265 [CALAMRDG 138]   -0.286     
79400 [DES.MINE 138]   -0.285      65086 [ASHLEY  69.0]   -0.284     
79067 [VERNAL   138]   -0.277      67257 [MOONLAK269.0]   -0.268     
67256 [MOONLAK169.0]   -0.266      79264 [W.RV.CTY 138]   -0.206     

'''

I am using “findall” to match the text using the pattern above and expect to extract a list of tuples. When I run this I am getting:

[('1.1800', 'DEVIATION', 'LENZIE 218.0'), ('1.5167', 'DEVIATION', 'HIPLN_G .575'),     ('1.1800', 'DEVIATION', 'W.RV.CTY 138')]

But I should be getting a lot more matched tuples in my list. I am really only interested in extracting the time on the first line of each match along with all the items in the square brackets “[]”. I should be getting 6+13+12 = 31 tuples in the list. Any help would be appreciated.

  • 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-06-11T02:47:53+00:00Added an answer on June 11, 2026 at 2:47 am

    What you want cannot be done using regular expressions. (At least, not in a single regular expression). The number of subgroups inside a group or a match cannot be variable. Compare this simplified version of your regular expression.

    p = re.compile('(a(b)+)')
    test3 = 'ababbabbbabbbb'
    print p.findall(test3)
    

    You want it to return something like this:

    [('ab', 'b'), ('abb', 'b', 'b'), ('abbb', 'b', 'b', 'b'), ('abbbb', 'b')]
    

    Instead it returns this:

    [('ab', 'b'), ('abb', 'b'), ('abbb', 'b'), ('abbbb', 'b')]
    

    Based on the example data, you could use a two pass algorithm. You could first use your original regular expression (without the grouping that makes it fail) to extract the big blocks of text. Then, using a second regular expression, you can extract the subpatterns from the blocks you found in the first pass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me why the following code fails to submit the form into
Can any one tell me the Regex pattern which checks for the empty span
Can anyone tell me what this bit of regex does? </?[a-z0-9-='!\$\?%&\*\+@~##;,\\]*:[a-z0-9 -='!\$\?%&\*\+@~##;,\\]*> My regex
Can anyone tell me if the following CSS is valid? .class { background-color:none; }
Can anyone tell me ow to format the text/document before I send it to
can anyone tell me the function of following code. is the code line NSString*
Can anyone tell me a regex to preg_replace all timestamps from a log file?
Can anyone tell me how to use regex to get templatefields out of a
Can anyone tell me what ?= does when using regex? Here is an example
I am new to RegEx. Can anyone tell me if it's possible to determine

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.