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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:39:20+00:00 2026-05-29T09:39:20+00:00

I am stuck at this error in pyparsing from pyparsing import Word,alphas,nums,Or,Regex,StringEnd ws =

  • 0

I am stuck at this error in pyparsing

from pyparsing import Word,alphas,nums,Or,Regex,StringEnd
ws = Regex('\s*')
dot = "."
w = Word(alphas) + (ws | dot) + StringEnd()
w.leaveWhitespace()
w.parseString('AMIT.')

Returns the following error:

ParseException: Expected end of text (at char 4), (line:1, col:5)
  • 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-29T09:39:21+00:00Added an answer on May 29, 2026 at 9:39 am

    | creates a “match first” expression, not “match longest”.

    The first alternative is the regex, which will match 0 or more whitespace characters. This, in fact, does match, so the dot is not parsed.

    Then the next element to parse is StringEnd, but the parse position is still located at the ‘.’—so, fail!

    Here is some more detailed output by adding setDebug() calls to your grammar expressions:

    >>> w = Word(alphas).setDebug() + (ws.setDebug() | dot.setDebug()) + StringEnd()
    >>> w.parseString('AMIT.')
    Match W:(abcd...) at loc 0(1,1)
    Matched W:(abcd...) -> ['AMIT']
    Match Re:('\\s*') at loc 4(1,5)
    Matched Re:('\\s*') -> ['']
    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 4), (line:1, col:5)
    

    To get your grammar to work you could:

    • change the | operator to ^ (match longest instead of match first)

    • change the regex to \s+ instead of \s* (so that at least one space was required for a match)

    • change your second term to Optional(dot)

    In general, explicit testing for whitespace is not consistent with the pyparsing philosophy—pyparsing is not the same as re.

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

Sidebar

Related Questions

I'm getting the error, SOAP-ERROR: Parsing Schema: can't import schema from ' http://schemas.xmlsoap.org/soap/encoding/ '
This may be a simple problem. But im totally stuck with this error. I
New to pthread programming, and stuck on this error when working on a C++&C
I m stuck with this error: Code Sign error: Certificate identity 'iPhone Developer: My
I got stuck by this error message because for three days I didn't find
I am stuck with this error: while trying to use an old DLL in
I am getting stuck with this error while building Ad hoc distribution profile. Application
I am stuck in this error, it displays this message in Chrome, and I
Temporary ASP.NET Files Missing I struck with this error at yesterday itself. I googled
I am getting this error: integerMultiplication.rb:4:in `untMul': stack level too deep (SystemStackError) in this

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.