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 February 18th, 2012, 11:19 AM
seamoon seamoon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 22 seamoon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 14 m 41 sec
Reputation Power: 0
Other - Replacing first three words

Hi I want to replace first three "Next" words to "Previous" as I shown below, I tried some tools but I couldn't what regexes should I use to do this?

Code:
					<li style="margin-right: 20px;">
								<a href="4.html" title="Next">
	<img src="../thumbs/4.JPG" alt="Next" />
	<h2>Next</h2>
	<div class="clear"></div>
</a>

					</li>
					<li style="margin-left: 20px;">
								<a href="6.html" title="Next">
	<img src="../thumbs/6.JPG" alt="Next" />
	<h2>Next</h2>




to this:

Code:
						<li style="margin-right: 20px;">
								<a href="4.html" title="Previous">
	<img src="../thumbs/4.JPG" alt="Previous" />
	<h2>Previous</h2>
	<div class="clear"></div>
</a>

					</li>
					<li style="margin-left: 20px;">
								<a href="6.html" title="Next">
	<img src="../thumbs/6.JPG" alt="Next" />
	<h2>Next</h2>

Reply With Quote
  #2  
Old February 18th, 2012, 01:44 PM
ragax's Avatar
ragax ragax is offline
Turn left at the third duck
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Location: Nelson, NZ
Posts: 93 ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 24 m 37 sec
Reputation Power: 92
Hi again Seamoon!

Please don't cross-post

I replied on the other post as the context made it clear that you are using php.

For reference for this board:

Search:
Code:
(?s)^(?>.*?\b\K(Next))\b(?>(.*?)\b(Next))\b(.*?)\bNext\b


Replace:
Code:
Previous\2Previous\4Previous


Wishing you a fun weekend.
__________________
Regex Tutorial | Latest RegexBuddy Demo

Reply With Quote
  #3  
Old February 18th, 2012, 02:43 PM
seamoon seamoon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 22 seamoon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 14 m 41 sec
Reputation Power: 0
Hi ragax, I get this error message:

Regular Expression Syntax Error
Unknown regex token \K. Use backslashes to escape metacharacters

P.S.
Ok, no cross-posting.

Reply With Quote
  #4  
Old February 18th, 2012, 03:11 PM
ragax's Avatar
ragax ragax is offline
Turn left at the third duck
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Location: Nelson, NZ
Posts: 93 ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 24 m 37 sec
Reputation Power: 92
Code:
Unknown regex token \K. 

\K only works since php 5.2.4, maybe you have an older version?

Here is a version without \K. Note that both the Search and the Replace have changed.

Search:
Code:
(?s)^(?>(.*?)\b(Next))\b(?>(.*?)\b(Next))\b(.*?)\bNext\b

Replace:
Code:
\1Previous\3Previous\5Previous

Let me know if you run into more problems.

Reply With Quote
  #5  
Old February 18th, 2012, 03:22 PM
seamoon seamoon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 22 seamoon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 14 m 41 sec
Reputation Power: 0
I'm using powergrep for replace operation. This time all nexts replaced by previous.


Code:
								<img src="../thumbs/5.JPG" alt="Previous" />
	<h2>Previous</h2>
	<div class="clear"></div>
</a>

					</li>
					<li style="margin-left: 20px;">
								<a href="7.html" title="Previous">
	<img src="../thumbs/7.JPG" alt="Previous" />
	<h2>Previous</h2>
	<div class="clear"></div>

Reply With Quote
  #6  
Old February 18th, 2012, 04:06 PM
ragax's Avatar
ragax ragax is offline
Turn left at the third duck
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Location: Nelson, NZ
Posts: 93 ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 24 m 37 sec
Reputation Power: 92
Not a PG expert, when I tried it I found the interface impossible to understand. (I have a much easier time with ABA Replace.) But that's my own limitation, I probably just need to study the manual. Anyhow...

In the PHP example on the other post, I gave preg_replace a 1 for the fourth parameter, meaning make one replacement. The same is probably possible in PG.

In the meantime, this is heavier but it should work.

Search:
Code:
(?s)\A(?>((?:(?!Next).)*)\b(Next))\b(?>((?:(?!Next).)*)\b(Next))\b((?:(?!Next).)*)\bNext\b

Replace:
Code:
\1Previous\3Previous\5Previous


Let me know if this solves it.

Last edited by ragax : February 18th, 2012 at 04:57 PM. Reason: performance tweak

Reply With Quote
  #7  
Old February 18th, 2012, 04:29 PM
seamoon seamoon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 22 seamoon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 14 m 41 sec
Reputation Power: 0
Yep, it worked great and saved me editing several hundreds of pages. Thanks thousands for your help and patience ragax!

Reply With Quote
  #8  
Old February 18th, 2012, 04:43 PM
ragax's Avatar
ragax ragax is offline
Turn left at the third duck
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Location: Nelson, NZ
Posts: 93 ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 24 m 37 sec
Reputation Power: 92
It's a pleasure, seamoon, glad it worked.
Please don't hesitate to ask if other questions arise.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Other - Replacing first three words

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