473,385 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Simple regular expression replace for picture URL

I need to replace picture links inside strings like this example :

blabla http://img146.imageshack.us/img126/6348/anything.jpg blabla
for
blabla [img:http://img146.imageshack.us/img126/6348/anything.jpg] blabla

I can found them with this regex without problems : ((http(s?):)|([/|.|\w|\s])*\.(?:jpg|gif|png)

My actual replace is : [img:$&]

I didn't find a way to put my last bracket at the very end of my url with my replace.

Thanks for your help
May 11 '10 #1

✓ answered by jhardman

This worked in my tests:
Expand|Select|Wrap|Line Numbers
  1. (http(s)?://)?[.\w]{3,}.(jpg|gif|png)

6 2967
jhardman
3,406 Expert 2GB
so is it showing up like this?

blabla [img:http:][img://img146.imageshack.us/img126/6348/anything.jpg] blabla
May 18 '10 #2
@jhardman
Right, exactly what I get.

I want to remove the ][ between http:// and not repeat img in my string...
May 19 '10 #3
jhardman
3,406 Expert 2GB
try this variation, it worked on my test, but I only tested one string.
Expand|Select|Wrap|Line Numbers
  1. (http(s?):)?([/|.|\w|\s])*\.(?:jpg|gif|png)
I just changed one symbol, making the http(s?): optional rather than "or".

Jared
May 21 '10 #4
jhardman
3,406 Expert 2GB
never mind, I found a flaw, I put two img urls with a word in between, and it recognized it all as one phrase. Let me think just a moment, we need to disallow spaces...
May 21 '10 #5
jhardman
3,406 Expert 2GB
This worked in my tests:
Expand|Select|Wrap|Line Numbers
  1. (http(s)?://)?[.\w]{3,}.(jpg|gif|png)
May 21 '10 #6
Thanks a lot, you save me lot of time learning RegEx (but still, I need to learn it anyway...)
May 25 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: peterbe | last post by:
I want to match a word against a string such that 'peter' is found in "peter bengtsson" or " hey peter," or but in "thepeter bengtsson" or "hey peterbe," because the word has to stand on its own....
3
by: EFP | last post by:
Can anyone help me with a simple regular expression problem. All that I want to do is take a list of known data and extract a particular section of the string to form a new list. Here is my...
2
by: Bryan Ax | last post by:
My regular expression inadequacies are surfacing again... I'm trying to write a simple regex to match either the character S, or the character O, or the phrase SP (but not the phrase SO, or SP,...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
3
by: George Yachán | last post by:
What would the regular expression be to return both of the following? Thank you. 'earns $21.25 from" 'earns $21 from"
6
by: alexrussell101 | last post by:
For anyone who can't be bothered to read my code and examples, scroll to the bottom, the question's there. Thanks. I'm using php and regular expressions to convert bbcode style things to html....
7
by: Joey | last post by:
Hello, I need a regular expression that will allow alpha-numeric characters, the underscore character, the period character, and the single quote character. The following is not working, for...
3
by: Joey | last post by:
I currently have a regular expression that will match textbox input for phone numbers formatted as ###-###-####. The expression is... \d{3}-\d{3}-\d{4} How can I modify this to accept the...
6
by: Zdenek Maxa | last post by:
Hi all, I would like to perform regular expression replace (e.g. removing everything from within tags in a XML file) with multiple-line pattern. How can I do this? where =...
1
by: python_enthu | last post by:
On Jun 27, 11:05 am, "John Salerno" <johnj...@NOSPAMgmail.comwrote: Thanks John Salerno and John Machin, I am used to perl. So I guess I am better of using re.search instead of re.match BTW,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.