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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:11:52+00:00 2026-06-08T14:11:52+00:00

I have to search the following patterns in a file, (any match qualifies) pattern_strings

  • 0

I have to search the following patterns in a file, (any match qualifies)

pattern_strings = ['\xc2d', '\xa0', '\xe7', '\xc3\ufffdd', '\xc2\xa0', '\xc3\xa7', '\xa0\xa0', '\xc2', '\xe9']
pattern = [re.compile(x) for x in pattern_strings]

and function using this

def find_pattern(path):
    with open(path, 'r') as f:
        for line in f:
            found = pattern.search(line)
            if found:
                logging.info('found - ' + found)

When I try using it

find_pattern('myfile')

I see AttributeError: "'list' object has no attribute 'search'"

because patterns is

[<_sre.SRE_Pattern object at 0x107948378>, <_sre.SRE_Pattern object at 0x107b31c70>, <_sre.SRE_Pattern object at 0x107b31ce0>, <_sre.SRE_Pattern object at 0x107ac3cb0>, <_sre.SRE_Pattern object at 0x107b747b0>, <_sre.SRE_Pattern object at 0x107b74828>, <_sre.SRE_Pattern object at 0x107b748a0>, <_sre.SRE_Pattern object at 0x107b31d50>, <_sre.SRE_Pattern object at 0x107b31dc0>]

How can I have one pattern which looks for all strings in pattern_strings?

  • 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-08T14:11:54+00:00Added an answer on June 8, 2026 at 2:11 pm

    You could simply concatenate all the expressions together with a |:

    pattern_strings = ['\xc2d', '\xa0', '\xe7', '\xc3\ufffdd', '\xc2\xa0', '\xc3\xa7', '\xa0\xa0', '\xc2', '\xe9']
    pattern_string = '|'.join(pattern_strings)
    pattern = re.compile(pattern_string)
    

    This does, however, assume that none of your patterns are complicated enough that a simple concatenation like this might break. For the ones in your example, it should work. For more complex patterns, it may not.

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

Sidebar

Related Questions

I have the following two patterns and need to find a match if either
I have the following problem: I have a search box in which user can
I have a search page with the following scenarios listed below. I was told
I have the following scenario. I have a search page which is split into
I am altering the question now! I have the search working using the following:
I have the following controller: public ActionResult Search(string Name, int? Friend, int? Page) It
I have the following code to recursively search for files through a directory, which
I have the following: string html_string = http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=pharma; string html; html = new WebClient().DownloadString(html_string);
I have the following named scope: named_scope :report_search, lambda { |search| { :conditions =>
I have to search from codebase of lines having following pattern: get_token , get_token

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.