Solved

Visual Studio 2005 Regular Expression Help

Posted on 2006-06-28
9
319 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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:…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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