Solved

Visual Studio 2005 Regular Expression Help

Posted on 2006-06-28
9
315 Views
Last Modified: 2008-03-06
In visual studio 2005 I am trying to replace all instances of
<img alt="????" src="?????">
with
<img alt="????" src="??????" />

I cannot figure out the appropriate regular expression to use to only find the image tags.

When i use \<img (.)*~(\\)\> it matches
<img alt="??????" src="???????"></td>

Can anyone tell me the right regular expression to use?
0
Comment
Question by:dave4dl
  • 5
  • 3
9 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 17005430
Hi dave4dl;

Try this Regex pattern (<img\s*alt\s*=\s*".*?"\s*src\s*=\s*".*?"\s*)(>)
And this replacement string "$1 /$2"

Fernando
0
 
LVL 15

Author Comment

by:dave4dl
ID: 17005527
Sorry, i should have been more clear.  I am using regular expressions in the visual studio IDE "Find/Replace" window.

In the visual studio IDE i need to do this find/replace on my code.

Fernando, the regular expression example you posted is not syntax for VS IDE regular expressions.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 17005689
Yes dave4dl; it makes a big difference Regex in the IDE and the Regex class. So now that I got it straight try this IDE Regex pattern:

        {\<img *alt *= *".@" *src *= *".@" *}{\>}

And this replace4ment string

        \1 /\2

Fernando
0
 
LVL 15

Author Comment

by:dave4dl
ID: 17005950
Thank you Fernando.  That looks like it would do some of the substitutions i want to do.

One more thing that I didnt state explicitly is that I would like to do this replacement (adding the "/" before the end of the img tag) on all img tags no matter what attributes are defined in them.

So
<img src=blah.gif> should become <img src=blah.gif />
and
<img alt="blah" border=10 src=hmm.jpg> should become <img alt="blah" border=10 src=hmm.jpg />

basically anything between an instance of "<img " and the very next ">" should be found (no matter what is between those two) except for the case where there is already a slash before the greater than sign "/>"
hence my example of
\<img (.)*~(\\)\>

basically the (.)* was taking too many and i wanted it to stop at the first ">"

\<img [^\>]*~(\\)\>
works ok but it finds cases where the slash-to-add is already present
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 17006062
OK then use this pattern:

        {\<img *[^/]+ *}{\>}

Replacement string:

        \1 /\2
       
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 17159960
Hi Bob;

I would like to see a resolution to this question seeming that dave4dl replied that the solution I gave worked and wanted to know another question and I gave dave4dl the answer.

Thanks;

Fernando
0
 
LVL 15

Author Comment

by:dave4dl
ID: 17170504
thanks for your help
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 17170519
No problem, thanks.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now