Solved

Visual Studio 2005 Regular Expression Help

Posted on 2006-06-28
9
316 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 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

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

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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