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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:22:43+00:00 2026-05-19T03:22:43+00:00

I want to match words that contain special characters or that begin with ‘http://’

  • 0

I want to match words that contain special characters or that begin with ‘http://’

So this sentence

%he#llo, my website is: http://www.url.com/abcdef123

should turn into this

my website

So far, i have this

re.sub(r"^[^\w]", " ", "%he#llo, my website is: http://www.url.com/abcdef123")

This just removes the symbols, but it doesn’t remove the words associated with the symbol (it also doesn’t remove ‘:’ and ‘,’), nor does it remove the URL.

  • 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-19T03:22:43+00:00Added an answer on May 19, 2026 at 3:22 am

    For the example string you give, the following regular expression works OK:

    >>> a = '%he#llo, my website is: http://www.url.com/abcdef123'
    >>> re.findall('(http://\S+|\S*[^\w\s]\S*)',a)
    ['%he#llo,', 'is:', 'http://www.url.com/abcdef123']
    

    … or you can remove those words with re.sub

    >>> re.sub('(http://\S+|\S*[^\w\s]\S*)','',a)
    ' my website  '
    

    The | means alternation and will match the expression on either side within the group. The part on the left matches http:// followed by one or more non-space characters. The part on the right matches zero or more non-space characters, followed by anything that isn’t a word or space character, followed by zero or more non-space characters — that ensures that you have a string with at least one non-word character and no spaces.

    Updated: Of course, as the other answers implicitly suggest, since the http:// prefix contains a non-word character (/) you don’t need to have that as an alternative – you could simplify the regular expression to \S*[^\w\s]\S*. However, perhaps the example above with alternation is still useful.

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

Sidebar

Related Questions

I want a Perl regular expression that will match duplicated words in a string.
I want to match expressions that begin with ${ and end with } in
I want to match multiline comments that contain a specific word, let's say findthis
In Java's regular expression, I want to match any sentence that contains the word
I want to match D11-RONPLAYER_DEF_15_PO using this regular expression: D\[0-9]+-\[A-Z]*PLAYER_(DEF\[0-9]*)_(\[^_]+)_ but it does not
I have a string containing words that i need to match like the one
I want to fetch records which contain a certain substring(set of words). My problem
I'm trying to come up with a regex that will match only words that
I'm trying to select posts using MATCH to find strings that contain the exact
I want to match pair of words where one of them changes constantly (loop

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.