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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:15:16+00:00 2026-06-08T04:15:16+00:00

The following prints ‘pass’: pattern = Word(alphanums) + StringEnd() str= bar results = pattern.parseString(str)

  • 0

The following prints ‘pass’:

pattern = Word(alphanums) + StringEnd()
str=" bar "
results = pattern.parseString(str)
if 1 == len(results) && "bar" == results[0] :
    print("pass")
else:
    print("fail")

but this throws and exception in parseImpl of class StringEnd (when the char following ‘r’ in ‘bar’ is not a string end):

pattern = Word(alphanums) + StringEnd()
str=" bar foo "
results = pattern.parseString(str)  # <-- exception raised

as does this:

pattern = Word(alphanums)
str = " bar foo"
results = pattern.parseString(str,parseAll=True)

I would expect the 2nd/3rd parseString calls to just return an empty array, as it would obviously not satisfy the grammer.

Can anyone help me understand why?

(should be obvious, but to run you’ll need ‘from pyparsing import *’; also I’m on python3.2 and pyparsing 1.5.6)

  • 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-08T04:15:18+00:00Added an answer on June 8, 2026 at 4:15 am

    Returning an empty list on a failed match is ambiguous – did the grammar match and just return an empty match, or did it not match at all?

    >>> from pyparsing import *
    >>> integer = Word(nums)
    >>> expr = Suppress("data:") + ZeroOrMore(integer) + StringEnd()
    

    Parse some data:

    >>> expr.parseString("data: 1 2 3").asList()
    ['1', '2', '3']
    

    Successful parse, there just weren’t any numbers here:

    >>> expr.parseString("data:").asList()
    []
    

    Exception tells you this match failed:

    >>> expr.parseString("data: 4 Z 6 7").asList()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "c:\python26\lib\site-packages\pyparsing-1.5.6-py2.6.egg\pyparsing.py", line 1032, in parseString
        raise exc
    pyparsing.ParseException: Expected end of text (at char 12), (line:1, col:13)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code prints out 10 . How can I make it print out
The following code prints (when invoking MyMethod): 0 0 0 1 I would expect
The following code prints null once. class MyClass { private static MyClass myClass =
For example the following code prints { key: 'b' } function myFunc(key, value) {
Why is the following code prints xxY? Shouldn't local variables live in the scope
The following java code prints Hello World on my co-worker's computer: public void testJDBC()
The following one liner prints out the content of the file in reverse $
The program below prints the following data: Wed,Jun,13,10:37:34,2012,759,41,0,30,10,0,0,1 Wed,Jun,13,10:38:34,2012,767,33,0,25,6,0,0,2 Wed,Jun,13,10:39:34,2012,758,42,0,32,10,0,0,0 Wed,Jun,13,10:40:35,2012,758,42,0,29,11,0,0,2 Wed,Jun,13,10:41:35,2012,761,39,0,34,5,0,0,0 Wed,Jun,13,10:42:35,2012,769,31,0,22,6,0,0,3 Wed,Jun,13,10:43:35,2012,754,46,0,29,17,0,0,0
This popup prevent other scripts from running and prints the following: instruments[2596] : kCGErrorInvalidConnection:
I have a CGI script that prints the following on stdout: print Status: 302

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.