Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regular Expressions

Posted on 2006-11-01
5
Medium Priority
?
212 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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