Solved

Visual Studio 2005 Regular Expression Help

Posted on 2006-06-28
9
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 63

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 63

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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
 
LVL 63

Accepted Solution

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

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

Replacement string:

        \1 /\2
       
0
 
LVL 63

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 63

Expert Comment

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

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

726 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