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 May 23rd, 2012, 06:38 PM
RRWD RRWD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 3 RRWD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 8 sec
Reputation Power: 0
Search on one thing and replace another

For this line of html, the search is for the "24pt" and if it exists then replace its <p> tags with <h1> tags.

<p style="font-size:24pt">Heading</p>
<p style="font-size:12pt">Some text</p>
<p style="font-size:12pt">Some more text</p>
<p style="font-size:24pt">Another Heading</p>

Would become:

<h1 style="font-size:24pt">Heading</h1 >
<p style="font-size:12pt">Some text</p>
<p style="font-size:12pt">Some more text</p>
<h1 style="font-size:24pt">Another Heading</h1 >


I'm using Expresso but just cannot get there... Any help would be MUCH appreciated.

Ron

Reply With Quote
  #2  
Old May 23rd, 2012, 07:21 PM
spacebar208's Avatar
spacebar208 spacebar208 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: spaceBAR Central
Posts: 191 spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 9 h 55 m 30 sec
Reputation Power: 41
This is an example of using sed to do the replacement for you:
Code:
$ echo '<p style="font-size:24pt">Heading</p>' | sed  's/^<p\(.*\)<\/p>$/<h1\1<\/h1>/'
<h1 style="font-size:24pt">Heading</h1>


If that is what you want, you can run it over your file:
Code:
sed  's/^<p\(.*\)<\/p>$/<h1\1<\/h1>/' file_in.txt > file_out.txt

Reply With Quote
  #3  
Old May 23rd, 2012, 07:43 PM
RRWD RRWD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 3 RRWD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 8 sec
Reputation Power: 0
I should have been explicit, I need to use regex find and replace, similar to Expresso. I'm using a program that converts MS Word files to CSV with HTML and that takes direct regex code.

Reply With Quote
  #4  
Old May 24th, 2012, 12:05 AM
spacebar208's Avatar
spacebar208 spacebar208 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: spaceBAR Central
Posts: 191 spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 9 h 55 m 30 sec
Reputation Power: 41
I just looked at info for Expresso(ultrapico.com/Expresso.htm) and the site info says it uses the ".net" flavor of the regular expression engine and if that is true then you can use this as the regular expression to find the lines:
Code:
^<p(.*)</p>$

And this as the substitution or replacement:
Code:
<h1\1<\/h1>

Reply With Quote
  #5  
Old May 24th, 2012, 08:45 AM
RRWD RRWD is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 3 RRWD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 8 sec
Reputation Power: 0
Thanks for clarification. And, how would that be for only lines with "font-size: 24pt" ?

Reply With Quote
  #6  
Old May 24th, 2012, 04:58 PM
spacebar208's Avatar
spacebar208 spacebar208 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: spaceBAR Central
Posts: 191 spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 9 h 55 m 30 sec
Reputation Power: 41
Just hard code into the regular expression the text that should be found, For example:

Code:
^<p style="font-size:24pt">(.*)</p>$

Assert position at the beginning of the string «^»
Match the characters “<p style="font-size:24pt">” literally «<p style="font-size:24pt">»
Match the regular expression below and capture its match into backreference number 1 «(.*)»
   Match any single character that is not a line break character «.*»
      Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the characters “</p>” literally «</p>»
Assert position at the end of the string (or before the line break at the end of the string, if any) «$»

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Search on one thing and replace another

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