Solved

Regular Expressions

Posted on 2006-11-01
5
210 Views
Last Modified: 2010-04-16
Hi

How can replace all text in tags that starts with

 <td background="Images/top.gif">

and parse the content of (my_own_string_text) variable

String my_own_string_text ='test.gif';

<td background='test.gif'>

vbturbo
0
Comment
Question by:vbturbo
[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
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17848904
Hi, try:

using System.Text.RegularExpressions;

...

string inputData = "your html data here";
string my_own_string_text = "\"test.gif\"";

inputData = Regex.Replace(inputData, "(<td background=)\".+?\"([^>]*>)", "$1" + my_own_string_text + "$2");


0
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17848949
This one would be better

inputData = Regex.Replace(inputData, "(<td.*?background=)\".+?\"", "$1" + my_own_string_text);
0
 
LVL 18

Author Comment

by:vbturbo
ID: 17849522
Thanks Zephyr

one final question

if i want produce/ and parse single quotes instead of double quotes

like this

'test.gif'

instead of

"\"test.gif\""

0
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 500 total points
ID: 17849600
Hi, use the following, the regex should now match single and double quotes in the input:

...
inputData = Regex.Replace(inputData, "(<td.*?background=)(\"|').+?(\"|')", "$1" + my_own_string_text);

The replacement string just needs to be surrounded with whatever quotes you want to use, for single quotes use:

string my_own_string_text = "'test.gif'";

Hope this helps!
0
 
LVL 18

Author Comment

by:vbturbo
ID: 17849960
Thanks a lot
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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