Solved

Regular Expressions

Posted on 2006-11-01
5
205 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
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Ravi Singh
Comment Utility
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
Comment Utility
This one would be better

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

Author Comment

by:vbturbo
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

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