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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:39:20+00:00 2026-05-29T17:39:20+00:00

I have a string which could be arbitrary long say s = ‘Choose from

  • 0

I have a string which could be arbitrary long say

s = 'Choose from millions of possibilities on Shaadi.com. Create your profile, search&contact; your special one.RegisterFree\xa0\xa0\xa0unsubscribing reply to this mail\xa0\n and 09times and this is limited time offer! and this is For free so you are saving cash'

I have a list of spam words which could be like

p_words = ['cash', 'for free', 'limited time offer']

All I want to know if there pattern exists in the input text and how many times?

It becomes simple when it has just one word

import re
p = re.compile(''.join[p_words])  # correct me if I am wrong here
m = p.match(s)  

but it could be a bi-gram, tri-gram or n-gram

How do we approach this?

  • 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-29T17:39:21+00:00Added an answer on May 29, 2026 at 5:39 pm

    If the text and number of words is not very large you could start with, example:

    d = {w: s.count(w) for w in p_words if w in s}
    # -> {'cash': 1, 'limited time offer': 1}
    

    You could compare its performance with:

    import re
    from collections import Counter
    
    p = re.compile('|'.join(map(re.escape, p_words)))
    d = Counter(p.findall(s))
    # -> Counter({'limited time offer': 2, 'cash': 2})
    

    For reference compare its speed with fgrep. It should be fast at matching multiple strings in the input stream:

    $ grep -F -o -f  patternlist.txt largetextfile.txt  | sort | uniq -c
    

    Output

      2 cash
      2 limited time offer
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string which could contain several different values, among them are. EDITED
Ok basically I have a string which could be anything but for the purposes
I have a string which could be like this: $searchterm = The quick brown
I have a String which can be very long so I want to split
I have a string which is like this: this is "a test" I'm trying
I have a string which contain tags in the form < tag > .
I have a string which starts with //#... goes upto the newline characater. I
I have a String which I would like to modify in some way. For
I have a string which holds a decimal value in it and I need
I have the string which that encoded in quoted-printable . How do I decode

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.