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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:05:55+00:00 2026-05-15T16:05:55+00:00

Given a pattern p and a string s, suppose p is in lower case.

  • 0

Given a pattern p and a string s, suppose p is in lower case. Which of the following two is more efficient?

r = re.compile(r'p', RE.IGNORECASE)
r.match(s)

… or …

r = re.compile(r'p')
r.match(s.lower())
  • 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-15T16:05:56+00:00Added an answer on May 15, 2026 at 4:05 pm

    It’s really going to depend on the language and engine. s.lower() and re.IGNORECASE are generally only slow because they’re trying to deal with localization or Unicode strings (see this question). If the regex package you’re using deals with that, and the s.lower() method doesn’t, then the s.lower() method is a clear win. And vice-versa.

    In general, I’d expect the s.lower() method to be faster (it tends to be more optimized than regex matching). But in the example as given …

    r = re.compile(r'[Pp]')
    r.match(s)
    

    … is going to be faster than either of them.

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

Sidebar

Ask A Question

Stats

  • Questions 493k
  • Answers 493k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Having both static and dynamic memory modes seems to me… May 16, 2026 at 10:53 am
  • Editorial Team
    Editorial Team added an answer you can check the dictionary view ALL_SEQUENCES (or USER_SEQUENCES if… May 16, 2026 at 10:53 am
  • Editorial Team
    Editorial Team added an answer The examples provided with Pyparsing include several expression parsers: https://github.com/pyparsing/pyparsing/blob/master/examples/fourFn.py… May 16, 2026 at 10:53 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Suppose I had the string 1 AND 2 AND 3 OR 4, and want
The task I was trying to accomplish was that given an input pattern, e.g.
Given a tabbed delimited text file with two columns name and date: Sam 20100101
Here's a Java generic pattern: public <T> T getResultData(Class<T> resultClass, other_args) { ... return
Let's take a concrete example and hope I can be clear. Suppose the (ordered)
I have a requirement to create some objects that implement a given interface, where
I am evaluating options for efficient data storage in Java. The data set is
Executive Summary: preg_replace() ran faster than string comparisons. Why? Shouldn't regular expressions be slower?
A set of APIs that I commonly use follow a linked-list pattern: struct SomeObject
I am trying to implement a php script which will run on every call

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.