Regex find urls and replace with bbcode - regex

I'm writing program that replace link with bbcode. I need a regex that replace url with bbcode, example:
before
http://mediafire.com/abc (or http://dropbox.net/abc,...)
I want to filter that name of link also
after
[url=http://name-of-link.com/abc]http://name-of-link.com/abc[/url]
This is what I have got so far:
Search for:
(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,#?^=%&:\/~+#-]*[\w#?^=%&\/~+#-])?
Replace with:
[url=$1]$2[/url]
But it seems doesn't work. Hope anyone can help me out this issue. Thank you.
Edit:
My issue that I want to filter name of link also, because I don't want to replace link of image to bbcode.

Related

regex to remove hyperlinks

Input:
source http://www.emaxhealth.com/1275/misdiagnosing from here http://www.cancerresearchuk.org/about-cancer/type recounting her experiences and thoughts blog http://fty720.blogspot.com even carried the new name. She was far from home.
From the about input I want to remove the hyperlinks. Below is the regex that I am trying
http://[\w|\W|\d|\s]*(?=[ ])
This regex will encompass all characters,digits and whitespaces after encountering the word 'http' and will continue till first blank space.
Unfortunately, it is not working as expected. Please do help me find out my error.Thanks
Try this sed command
sed 's/http[^ ]\+//g' FileName
Output :
source from here recounting her experiences and thoughts blog even carried the new name. She was far from home.
To find the hyperlink use:
\b(https?)://[A-Z0-9+&##/%?=~_|$!:,.;-]*[A-Z0-9+&##/%=~_|$]
or:
If you want to find the html a tag use:
<a\b[^>]*>(.*?)</a>

notepad ++ replacement expression

Hi guys I really need some help, I need to do a mass replace expression in files
I have a large list of urls which needs to be replaced.
I want to search files and replace each with the appropriate brand anchor link e.g.
http://www.example.com
becomes
<a href=”http://www.example.com”> http://www.example.com</a>
I need to do this with a large list of urls in multiple files
I tried the following expression
(1)|(2)|(3)
(?1a)(?2b)(?3c)
But It doesn’t work. This is beyond me. Any help would be appreciated. Thanks
Go to Search > Replace menu (shortcut CTRL+H) and do the following:
Find what:
http:\/\/www\.\w+\.com
Replace:
$0
Select radio button "Regular Expression"
Then press Replace All in All Opened Documents
You can test it and see the results at regex101.
Important note: matching URLs with regular expressions can be complicated! I gave you the simplest example matching only URLs like http://www.example.com. If you have more complicated stuff, let us know but showing some of your data! More info on this matter here and here.
UPDATE:
Let's make it slightly more complicated to match also
yoursite.com/index.php?remainingurl
Find what:
(?:https?:\/\/)?(?:www\.)?(\w+\.\w{2,6})(?:\/\w+\.\w+(?:\?\w+)?)?\b
Replace:
$1

What is the regex for a URL like this?

I don't really know regex, but would like a quick solution to search and replace links. I want to use the search regex wordpress plugin to remove links in my post. How do I format the regex to a link like this:
http://website.com/index.php?id=934&title=item name
edit: the numbers in the id and the item name varies
Thank you in advance!
Try this one out: http://regexr.com?2vjq6
Depending on whether or not you need whitespace in your "title" parameter, the regex I provided may need to be altered. Best practice would be to not have whitespace in your URLs (use URL encoding instead, where a space = %20).
http://website.com/index.php\?id=[0-9]*&title=[a-zA-Z0-9\-]*
Try this pattern
(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,#?^=%&:/~\+#]*[\w\-\#?^=%&/~\+#])?

regex for 3 numbers after string

I've a problem, I have a link on each page of my website linking to a different contact form which does'nt exist. for example, on one page it links to contact_123.html, another contact_122.html, another contact_124.html etc... I want to do a find and replace on this to change any contact_"any 3 numbers".html to just contact.html.
Does anyone know the regex to do this. Cheers!
Regex to search for: contact_\d{3}\.html
How to do actual search&replace depends what tool/environment you're using

I am trying to create an expression that will extract URLs

I want to extract URLs from a webpage these are just URLs by themselves not hyperlinks etc., they are just text. Some examples would be http://www.example.com, http://example.com, www.example.com etc. I am extremely new at regex so I have copy and pasted like 20 expressions online all failed to work. I don't know if I am doing it right or not. Any help would be really appreciated.
I wrote a post on using Regex to locate links within a HTML page (the intent was to use JavaScript to open external links or links to documents such as PDF's etc in a popup window).
The final regex was:
^(?:[./]+)?(?:Assets|https?://(?!(?:www.)?integralist))
The full post is here:
http://www.integralist.co.uk/javascript/regular-expression-to-open-external-links-in-popup-window/
The solution wont be perfect but might help point you in the right direction.
Mark
You're probably not escaping your .s. You need to use \. for each one.
Take a look at strfriend.com. It has a URL example, and represents it graphically.
The example it suggests is:
^((ht|f)tp(s?)://|~/|/)?(\w+:\w+#)?([a-zA-Z]{1}([\w-]+.)+(\w{2,5}))(:\d{1,5})?((/?\w+/)+|/?)(\w+.\w{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?