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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:22:13+00:00 2026-06-04T14:22:13+00:00

From what I figured, match : given a string str and a pattern pat,

  • 0

From what I figured,

match: given a string str and a pattern pat, match checks if str matches the pattern from str’s start.

search: given a string str and a pattern pat, search checks if str matches the pattern from every index of str.

If so, is there a meaning using '^' at the start of a regex with match?

From what I understood, since match already checks from the start, there isn’t. I’m probably wrong; where is my mistake?

  • 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-04T14:22:14+00:00Added an answer on June 4, 2026 at 2:22 pm

    When calling the function re.match specifically, the ^ character does have little meaning because this function begins the matching process at the beginning of the line. However, it does have meaning for other functions in the re module, and when calling match on a compiled regular expression object.

    For example:

    text = """\
    Mares eat oats
    and does eat oats
    """
    
    print re.findall('^(\w+)', text, re.MULTILINE) 
    

    This prints:

    ['Mares', 'and']
    

    With a re.findall() and re.MULTILINE enabled, it gives you the first word (with no leading whitespace) on each line of your text.

    It might be useful if doing something more complex, like lexical analysis with regular expressions, and passing into the compiled regular expression a starting position in the text it should start matching at (which you can choose to be the ending position from the previous match). See the documentation for RegexObject.match method.

    Simple lexer / scanner as an example:

    text = """\
    Mares eat oats
    and does eat oats
    """
    
    pattern = r"""
    (?P<firstword>^\w+)
    |(?P<lastword>\w+$)
    |(?P<word>\w+)
    |(?P<whitespace>\s+)
    |(?P<other>.)
    """
    
    rx = re.compile(pattern, re.MULTILINE | re.VERBOSE)
    
    def scan(text):
        pos = 0
        m = rx.match(text, pos)
        while m:
            toktype = m.lastgroup
            tokvalue = m.group(toktype)
            pos = m.end()
            yield toktype, tokvalue
            m = rx.match(text, pos)
    
    for tok in scan(text):
        print tok
    

    which prints

    ('firstword', 'Mares')
    ('whitespace', ' ')
    ('word', 'eat')
    ('whitespace', ' ')
    ('lastword', 'oats')
    ('whitespace', '\n')
    ('firstword', 'and')
    ('whitespace', ' ')
    ('word', 'does')
    ('whitespace', ' ')
    ('word', 'eat')
    ('whitespace', ' ')
    ('lastword', 'oats')
    ('whitespace', '\n')
    

    This distinguishes between types of word; a word at the beginning of a line, a word at the end of a line, and any other word.

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

Sidebar

Related Questions

So, I figured out how to get an access token from Google using the
I can't figure out how to give re.match() an individual line from a txt
Edit 4: the problem came from using the string name of the column instead
How would I write a function to move from point1 to point2 given some
I'm trying to lookup DbType enumeration values from .net types. I'm using a match
From the following HTML I need to figure out which List tag has class
I cannot figure out how to convert this code from C# to VB.net. It
I couldn't figure out that from SASS documentation. For example I would like to
Still trying to figure this out from yesterday. I am trying to scroll an
I am looking to figure out what my IP address is from a console

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.