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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:35:25+00:00 2026-06-16T00:35:25+00:00

I have an interesting issue going on with trying to understand and improve my

  • 0

I have an interesting issue going on with trying to understand and improve my use of REGEX in Python

here is a regular expression

verbose_signature_pattern_2 = re.compile("""
^            # begin match at new line
\t*          # 0-or-more tab
[ ]*         # 0-or-more blankspaces
S            # capital S
[iI][gG][nN][aA][Tt][uU][rR][eE]
[sS]?        # 0-or-1 S
\s*          # 0-or-more whitespace
[^0-9]       # anything but [0-9]
$            # newline character
""", re.VERBOSE|re.MULTILINE)

When I run the code I get an error

""", re.VERBOSE|re.MULTILINE)
  File "C:\Python27\lib\re.py", line 190, in compile
return _compile(pattern, flags)
File "C:\Python27\lib\re.py", line 242, in _compile
raise error, v # invalid expression
error: nothing to repeat

if I get rid of the 0-or-more qualifier on the tab (\t) special character it does not throw the error

Ii am trying to find lines that have some variant of the word Signature on them as the first word in the line. I know I could use a slightly different approach and get what I need. However I am imagining that the creator of the document might tab over to approximately center the word or they might use spaces. I do not want to use \s because I do not want to capture all of the empty lines that could precede the line that has the word Signature. Specifically I am trying to avoid capturing all of this crud

'\n\n\n\n            Signature    \n

I only want to see this in the output

'            Signature    \n

I do realize I can easily strip off the excess new-line characters but I am trying to understand and do things more precisely. The interesting thing is that the following REGEX has the same start but it seems to be working as expected. That is I am not getting an error when this one compiles and it seems to be giving me what I want – though I still need to find some more edge cases.

verbose_item_pattern_2 = re.compile(r"""
^            # begin match at newline
\t*          # 0-or-more tabs
[ ]*         # 0-or-more blanks
I            # a capital I
[tT][eE][mM] # one character from each of the three sets this allows for unknown case
\t*          # 0-or-more tabs
[ ]*         # 0-or-more blanks
\d{1,2}      # 1-or-2 digits
[.]?         # 0-or-1 literal .
\(?          # 0-or-1 literal open paren
[a-e]?       # 0-or-1 letter in the range a-e
\)?          # 0-or-1 closing paren
.*           # any number of unknown characters so we can have words and punctuation
[^0-9]       # anything but [0-9]
$            # 1 newline character
""", re.VERBOSE|re.MULTILINE)
  • 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-16T00:35:26+00:00Added an answer on June 16, 2026 at 12:35 am

    The first string is not a raw string. So when Python compiles the string (before it goes to the regex engine) it replaces all escape sequences. So \t will actually become a tab character in the string (not backslash-t). But you are using freespacing mode (re.VERBOSE). Therefore whitespace is insignificant. Your regex is equivalent to:

    ^*[ ]*S[iI][gG][nN][aA][Tt][uU][rR][eE][sS]?\s*[^0-9]$
    

    \s stays \s, even in a non-raw string, because it is not a recognized escape-sequence in Python strings.

    Then right at the beginning ^* is causing the problem, because you cannot repeat the anchor.

    This is why you should always use raw strings to write regular expressions. Then \t just stays backslash-t and the regex engine can interpret it as a tab.

    The space in [ ] is not a problem, by the way, since even in verbose/freespacing mode, spaces in character classes are significant.

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

Sidebar

Related Questions

Someone please help. I have an interesting issue. I am trying to implement an
I have ran into an interesting issue while trying to create a more usable
I have an interesting issue :/ I use CodeIgniter and the code below is
Here is an interesting issue I noticed when using the Except Operator: I have
I have an interesting issue with HTTPS ports not being handled properly. It is
I have a rather interesting issue with SVG animation. I am animating along a
I ran across an interesting issue today. We have an application that utilizes Zend
I have an issue with importing the scipy.special package. It isn't harmful, just annoying/interesting.
I have interesting question. According to MSDN yield syntax : yield return <expression>; //
Here we have an interesting real-world algorithm requirement involving colors. N Pretty Colors :

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.