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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:51:27+00:00 2026-05-22T23:51:27+00:00

I want to search for a regex match in a larger string from a

  • 0

I want to search for a regex match in a larger string from a certain position onwards, and without using string slices.

My background is that I want to search through a string iteratively for matches of various regex’s. A natural solution in Python would be keeping track of the current position within the string and using e.g.

re.match(regex, largeString[pos:])

in a loop. But for really large strings (~ 1MB) string slicing as in largeString[pos:] becomes expensive. I’m looking for a way to get around that.

Side note: Funnily, in a niche of the Python documentation, it talks about an optional pos parameter to the match function (which would be exactly what I want), which is not to be found with the functions themselves :-).

  • 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-22T23:51:28+00:00Added an answer on May 22, 2026 at 11:51 pm

    The variants with pos and endpos parameters only exist as members of regular expression objects. Try this:

    import re
    pattern = re.compile("match here")
    input = "don't match here, but do match here"
    start = input.find(",")
    print pattern.search(input, start).span()
    

    … outputs (25, 35)

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

Sidebar

Related Questions

I want to search a directory for all files that match a certain pattern.
From this question How to match this using regex Right now i want to
I have a string and a pattern that I want to search for in
I am trying to remove from a string using Regex. I am receiving a
I want to match any string that starts with a quote and then ends
I want a regex to match words that are delimited by double or more
I want to search a file in the current directory from which the batch
I want to search the program >> that is by which you append to
I have a string of codes like: 0926;0941;0917;0930;094D; I want to search for: 0930;094D;
I have a regex to match middle names that looks like this : first_name

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.