Solved

Visual Studio 2005 Regular Expression Help

Posted on 2006-06-28
9
310 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
OK then use this pattern:

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

Replacement string:

        \1 /\2
       
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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
Comment Utility
thanks for your help
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
No problem, thanks.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

11 Experts available now in Live!

Get 1:1 Help Now