473,473 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

regular expression - injecting div, and removing later

Hi all,

I'm having trouble trying to figure out the best approach to this
problem and I believe regular expressions are the way to go.

Basically I have created a large string of XHTML using a WYSIWYG editor,
so the string is like "<p>dfdsfjhds <img src='temp.jpg' />
dsfdsfsd</p><p>dfsdfsdfsd</p... "

What I want to do is the following...

When SAVING the string to the database I want to replace:

<img class="myImg" alt="" src="image.jpg" />

with...

<div class="cnt_myImg_left">
<div class="inner">
<img class="myImg" alt="" src="image.jpg" />
<p class="sub_text detail">my picture</p>
</div>
</div>
and when EDITING the string, I want to reinstate the original ....so
replace:

<div class="cnt_myImg_left">
<div class="inner">
<img class="myImg" alt="" src="image.jpg" />
<p class="sub_text detail">my picture</p>
</div>
</div>

with...

<img class="tmceImg" alt="" src="image.jpg" />
Does anyone know the best approach to this?

Many thanks!
Peter
--

fiddlewidawiddum
Aug 2 '08 #1
2 1547
On Aug 2, 12:08*pm, Stimp <r...@spumco.comwrote:
Hi all,

I'm having trouble trying to figure out the best approach to this
problem and I believe regular expressions are the way to go.

Basically I have created a large string of XHTML using a WYSIWYG editor,
so the string is like "<p>dfdsfjhds <img src='temp.jpg' />
dsfdsfsd</p><p>dfsdfsdfsd</p... "

What I want to do is the following...

When SAVING the string to the database I want to replace:

<img class="myImg" alt="" src="image.jpg" />

with...

<div class="cnt_myImg_left">
*<div class="inner">
* *<img class="myImg" alt="" src="image.jpg" />
* *<p class="sub_text detail">my picture</p>
*</div>
</div>

and when EDITING the string, I want to reinstate the original ....so
replace:

<div class="cnt_myImg_left">
*<div class="inner">
* *<img class="myImg" alt="" src="image.jpg" />
* *<p class="sub_text detail">my picture</p>
*</div>
</div>

with...

<img class="tmceImg" alt="" src="image.jpg" />

Does anyone know the best approach to this?

Many thanks!
Peter
--

fiddlewidawiddum
Well, I think you already found that this can be done using
Regex.Replace function. It allows replacement of text using regular
expressions. Not only can you define the text to replace using a
regular expression, you can define what to replace it with using a
replacement string containing special constructs which identify
portions of the mathed text.

More about this function
http://msdn.microsoft.com/en-us/libr...x.replace.aspx
Aug 2 '08 #2
On Sat, 2 Aug 2008 Alexey Smirnov <al************@gmail.comwrote:
On Aug 2, 12:08*pm, Stimp <r...@spumco.comwrote:

Well, I think you already found that this can be done using
Regex.Replace function. It allows replacement of text using regular
expressions. Not only can you define the text to replace using a
regular expression, you can define what to replace it with using a
replacement string containing special constructs which identify
portions of the mathed text.

More about this function
http://msdn.microsoft.com/en-us/libr...x.replace.aspx

thanks worked a charm! - plus I learned some regex.. bonus :)

--

fiddlewidawiddum
Aug 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris Lasher | last post by:
Hello, I would like to create a set of very similar regular expression. In my initial thought, I'd hoped to create a regular expression with a variable inside of it that I could simply pass a...
3
by: Tom | last post by:
I have struggled with the issue of whether or not to use Regular Expressions for a long time now, and after implementing many text manipulating solutions both ways, I've found that writing...
11
by: Ron Rohrssen | last post by:
Slightly off topic.... How can I write a regex that limits user input to 3 digits in the range of 1-128? I've been trying \d{1,128} but this allows for a match on more than 3 digits. ...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
6
by: Schorschi | last post by:
This one has got me bam-boz-ald! or however your spell it... I have a sequence of text for example, "One Two Three Four Three Two One Three", and I need a regular expression, if possible, to...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
6
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description:...
12
by: FAQEditor | last post by:
Anybody have any URL's to tutorials and/or references for Regular Expressions? The four I have so far are: http://docs.sun.com/source/816-6408-10/regexp.htm...
5
by: Noah Hoffman | last post by:
I have been trying to write a regular expression that identifies a block of text enclosed by (potentially nested) parentheses. I've found solutions using other regular expression engines (for...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.