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 January 15th, 2009, 06:32 PM
bsiariel bsiariel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 4 bsiariel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 13 m 5 sec
Reputation Power: 0
Total regex noob... Is this possible?

Here's my situation: I have code that looks like this:

Code:
previous: <A href="../Statutes/Title01/Chapter10/Section110.htm">Section 110</A>. Effect of Amendments to Statehood Act.<BR>
next: <A href="../Statutes/Title02/Chapter05.htm">Chapter 5</A>. Alaska Air Commerce Act of 1960<BR>


This little section is on about 40,000 pages, each "previous" and "next" link is going to be different on each page. What I'm trying to do is change all this code such that "previous/next", plus an arrow image, is INSIDE the link.

So, will a regex let me say:
"find 'previous:', and then find the next '>'"? This would allow me to replace the closing > of the link with what I actually want inside the link, without changing it for every link everywhere else.

I've looked at the 'lookaround' options, but those seem like it will only match *directly* before or after a character.

Can a regex 'skip' over parts of a line to find the match?

Help me!

Reply With Quote
  #2  
Old January 15th, 2009, 07:40 PM
requinix's Avatar
requinix requinix is online now
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,714 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 5 m 48 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Altering only the bits you want isn't always the solution. In fact, sometimes it just doesn't work.

How about you think of rearranging the line? Instead of
Code:
previous, <a>, inner text, </a>
you get
Code:
<a>, previous, inner text, arrow, </a>

It's not so much "moving the previous/next" as it is "moving everything".

Code:
Find     #(previous: )(<a[^>]+>)(.*?)</a>#i
Replace  $2&larr; $1$3</a>

Find     #(next: )(<a[^>]+>)(.*?)</a>#i
Replace  $2$1 &rarr;$3</a>

I don't know of a way you can conditionally add the left arrow or right arrow depending on whether it was a previous or next link. Thus two separate expressions. Maybe your language adds an extension to regular expressions to let you execute code as a replacement (like PHP's /e modifier).

Reply With Quote
  #3  
Old January 15th, 2009, 07:43 PM
bsiariel bsiariel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 4 bsiariel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 13 m 5 sec
Reputation Power: 0
Yes, ultimately that is what I want to do. Have the line read:

<a href="etc">[arrow img] previous: [current text]</a>

But your solution would first 'move' the 'previous' and 'next' words inside the link, and THEN I could go through and replace (with garden variety find/replace) 'previous' with '<img>previous'?

Reply With Quote
  #4  
Old January 15th, 2009, 08:30 PM
requinix's Avatar
requinix requinix is online now
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,714 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 5 m 48 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Quote:
Originally Posted by bsiariel
But your solution would first 'move' the 'previous' and 'next' words inside the link, and THEN I could go through and replace (with garden variety find/replace) 'previous' with '<img>previous'?

Not really: it moves everything around at the same time. One step.

Well, one step for the next link, one step for the previous link.

What language are you using? How familiar are you with regular expressions?

Reply With Quote
  #5  
Old January 16th, 2009, 05:23 PM
bsiariel bsiariel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 4 bsiariel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 13 m 5 sec
Reputation Power: 0
Not familiar with regular expressions at all. I've only just started learning about them, so total noob.

I'm not using any programming language, I'm trying to use the Find/Replace tool in Dreamweaver CS4, which supports regular expressions.

The code you've provided above doesn't end up matching or replacing anything when I test it on gskinner . com / regexr

I'll try dropping it in to Dreamweaver and see if something different happens.

Edit: Nope, Dreamweaver can't find with the above expression either.

Thanks for the handholding so far!

Last edited by bsiariel : January 16th, 2009 at 07:33 PM. Reason: Update

Reply With Quote
  #6  
Old January 16th, 2009, 07:41 PM
requinix's Avatar
requinix requinix is online now
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,714 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 5 m 48 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Wouldn't be surprised if those #s were an issue.

Just get the stuff in between them (drop that "i" at the end too) and look for a case-insensitive option.
In the replacement string $X marks a capture pattern. Basically, anything in the search string that's enclosed by ()s gets "captured" for use later. The first set of parentheses are $1 in the replacement, then $2, $3, and so on.
Dreamweaver might use a different symbol. I know some MS products use a backslash instead of a dollar sign (ie, \1, \2, \3, etc). If the replaced text looks odd then try that instead.

Of course, reading any documentation there might be would greatly help too. Mostly syntax: the principles and stuff you can find elsewhere.

Reply With Quote
  #7  
Old January 20th, 2009, 01:00 PM
bsiariel bsiariel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Posts: 4 bsiariel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 13 m 5 sec
Reputation Power: 0
Thanks! Removing the #s made it work!

You saved me a ton of /headdesking.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Total regex noob... Is this possible?

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