Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 15th, 2012, 03:18 AM
delboy31 delboy31 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 387 delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 13 h 8 m 24 sec
Reputation Power: 20
Other - Asp.net regex replace (VB)

Hi all. I'm trying to remove the <font face> tag but leave the data that is found within the tag intact. So far im using

PHP Code:
 story Regex.Replace(story"</?(font face)[^>]*>"string.Empty, RegexOptions.IgnoreCase


this works well, but it doesnt remove the </font> tag. how can i also remove the closing tag? thanks

Reply With Quote
  #2  
Old August 15th, 2012, 03:30 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,867 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 22 h 33 m 20 sec
Reputation Power: 813
Hi,

Since you require "face" in the pattern, a pure "font" tag won't be found.

This won't really work, anyway, because you'd need to find the exact end tag. That's not possible with regular expressions (if the elements can be nested).

The clean solution to this would be to use a HTML parser and actually remove the elements. Otherwise you'll have to mix the regex with a kind of tag counter to find the matching end tag (which is really not that pretty).

Reply With Quote
  #3  
Old August 15th, 2012, 03:34 AM
delboy31 delboy31 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 387 delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 13 h 8 m 24 sec
Reputation Power: 20
i see, what about leaving the font tags but simply removing anything found in "face" ?

eg
PHP Code:
<font face="arial">test</fontBECOMES.. <font>test</font


edit... done using
PHP Code:
 story Regex.Replace(story"font face=[^>]*""font"RegexOptions.IgnoreCase

Last edited by nshack31 : August 15th, 2012 at 03:49 AM.

Reply With Quote
  #4  
Old August 15th, 2012, 05:20 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,867 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 22 h 33 m 20 sec
Reputation Power: 813
Well, then I don't get what you're trying to do.

I thought you wanted to remove the tags of every "font" element with a "face" attribute? If you remove the attributes, you can no longer distinguish between "normal" font elements and those with a "face" attribute.

Reply With Quote
  #5  
Old August 15th, 2012, 05:42 AM
delboy31 delboy31 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 387 delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 13 h 8 m 24 sec
Reputation Power: 20
Quote:
Originally Posted by Jacques1
Well, then I don't get what you're trying to do.

I thought you wanted to remove the tags of every "font" element with a "face" attribute? If you remove the attributes, you can no longer distinguish between "normal" font elements and those with a "face" attribute.


the font family is standardised in the css so i didnt want any <font face> tags in the body over-riding this, but i wanted to keep font size and color tags

Reply With Quote
  #6  
Old August 15th, 2012, 01:12 PM
kaed kaed is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 5 kaed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 sec
Reputation Power: 0
Just add .replace("</font>", "") to the end of that line so its:
Code:
 story = Regex.Replace(story, "</?(font face)[^>]*>", string.Empty, RegexOptions.IgnoreCase).replace("</font>", "")


Good?

Reply With Quote
  #7  
Old August 16th, 2012, 03:42 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,867 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 22 h 33 m 20 sec
Reputation Power: 813
Quote:
Originally Posted by nshack31
the font family is standardised in the css so i didnt want any <font face> tags in the body over-riding this, but i wanted to keep font size and color tags


You're confusing the words. "font" is the HTML element, and "face", "color" etc. are attributes of this element.

So if I understand you correctly now, you want to remove the "face" attribute from any "font" element. The cleanest way for this would really be to use a DOM parser. Alternatively, you could try this pattern:

(<font[^>]+)face="[^"]"([^>]*>)

(You might need to escape the double quotes)

And then concatenate both matching groups to build the replacement string.

However, this will only find the attribute syntax
face="..."
It won't find face='...' or something. If you want that, too, the regular expression will become more and more complex.

Reply With Quote
  #8  
Old October 4th, 2012, 04:36 AM
delboy31 delboy31 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 387 delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level)delboy31 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 13 h 8 m 24 sec
Reputation Power: 20
sorry another question regarding something similar.

if i wanted to remove all instances of "font-family" e.g.

font-family:'Calibri','sans-serif';

i can use the following:

PHP Code:
 story Regex.Replace(story"font-family[^>]*"""""RegexOptions.IgnoreCase


but if the line was

PHP Code:
 line-height:115%;font-family:'Calibri','sans-serif';font-size:12pt 


it would become

PHP Code:
 line-height:115%; 


i'd need to leave the font-size in tact and only remove the font-family attribute

Last edited by nshack31 : October 4th, 2012 at 05:12 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Other - Asp.net regex replace (VB)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap