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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:00:13+00:00 2026-05-18T00:00:13+00:00

I’m trying to extract one or more urls from a plain text string in

  • 0

I’m trying to extract one or more urls from a plain text string in php. Here’s some examples

"mydomain.com has hit the headlines again"

extract ” http://www.mydomain.com“

"this is 1 domain.com and this is anotherdomain.co.uk but sometimes http://thirddomain.net"

extract “http://www.domain.com” , “http://www.anotherdomain.co.uk” , “http://www.thirddomain.net“

There are two special cases I need – I’m thinking regex, but dont fully understand them
1) all symbols like ‘(‘ or ‘)’ and spaces (excluding hyphens) need to be removed
2) the word dot needs to be replaced with the symbol . , so dot com would be .com

p.s I’m aware of PHP validation/regex for URL but cant work out how I would use this to achieve the end goal.

Thanks

  • 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-18T00:00:13+00:00Added an answer on May 18, 2026 at 12:00 am

    In this case it will be hard to get 100% correct results.
    Depending on the input you may try to force matching just most popular first level domains (add more to it):

    (?:https?://)?[a-zA-Z0-9\-\.]+\.(?:com|org|net|biz|edu|uk|ly|gov)\b
    

    You may need to remove the word boundary (\b) to get different results.

    You can test it here:

    http://bit.ly/dlrgzQ

    EDIT: about your cases
    1) remove from what?
    2) this could be done in php like:

     $result = preg_replace('/\s+dot\s+(?=(com|org|net|biz|edu|and_ect))/', '.', $input);
    

    But I have few important notes:

    • This Regex are more like guidance, not actual production code
    • Working with this kind of loose rules on text is wacky for the least – and adding more special cases will make it even more looney. Consider this – even stackoverflow doesn’t do that:

    http://example.org

    but not!

    example.org

    • It would be easier if you’d said what are you trying to achieve? Because if you want to process some kind of text that goes somewhere on the WWW later, then it is very bad idea! You should not do this by your own (as you said – you don’t understand Regex!), as this would be just can of XSS worms. Better think about some kind of Markdown language or BBCore or else.

    Also get interested in: http://htmlpurifier.org/

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.