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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:28:55+00:00 2026-06-11T05:28:55+00:00

I tried multiple solutions here, and although they strip some code, they dont seem

  • 0

I tried multiple solutions here, and although they strip some code, they dont seem to work on multiple punctuations ex. “[ or ‘,
This code:

regex = re.compile('[%s]' % re.escape(string.punctuation))
    for i in words:
        while regex.match(i):
            regex.sub('', i)

I got from:
Best way to strip punctuation from a string in Python was good but i still encounter problems with double punctuations.
I added While loop in hope to ittirate over each word to remove multiple punctuations but that does not seem to work it just gets stuck on the first item “[ and does not exit it

Am I just missing some obvious piece that I am just being oblivious too?

I solved the problem by adding a redundancy and double looping my lists, this takes extremely long time (well into the minutes) due to fairly large sets

I use Python 2.7

  • 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-11T05:28:57+00:00Added an answer on June 11, 2026 at 5:28 am

    Your code doesn’t work because regex.match needs the beginning of the string or complete string to match.

    Also, you did not do anything with the return value of regex.sub(). sub doesn’t work in place, but you need to assign its result to something.

    regex.search returns a match if the pattern is found anywhere in the string and works as expected:

    import re
    import string
    
    words = ['a.bc,,', 'cdd,gf.f.d,fe']
    
    regex = re.compile('[%s]' % re.escape(string.punctuation))
    for i in words:
        while regex.search(i):
            i = regex.sub('', i)
        print i
    

    Edit: As pointed out below by @senderle, the while clause isn’t necessary and can be left out completely.

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

Sidebar

Related Questions

I tried multiple solution but none seem to work. Layout: -------------------- |btn1| txt1 |btn2|
Ok, so i tried multiple of solutions but nothing seems to work for me,
I tried multiple HTTP classes ( HttpURLConnection , HTTPClient and others) but they don't
I want to tail multiple files (and follow them) in CentOS, I've tried this:
I tried to implement this. My original post is here iphone: playing audio playlist
There appears to be multiple ways to do this, but the examples I've tried
I've tried various things and googled multiple hours but couldn't find a solution to
I have already tried multiple ways. defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME=YourNameHere;}' Also i've tried
I've tried multiple functions to extract whatever between two strings, The delimiters might contain
Im getting an error with my SQL queries in PHP. I have tried multiple

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.