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 October 15th, 2012, 05:12 AM
sergiozambrano sergiozambrano is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 16 sergiozambrano Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 7 m 50 sec
Reputation Power: 0
Get recursion number or use result of group in later expression?

I need to match consecutive numbers, and repeat the same piece of regex as long as they keep incrementing, and what would really reduce my expression, 250+ characters long already! (or rather make it more elegant) would be to:

be able to use the result from one capture group in another expression later

or

to get the current iteration number and match other expressions against

PS: It HAS to be regex expression and replacement ONLY. A second search/replace pass is acceptable though.

example:

text 1 matches

text 2 matches

text 3 matches

text 6 doesn't match. end.

text 1 shouldn't even get here (or start over?)

- I heard about using backreferences in the same expression, as a conditional, and I heard about Recursions and matching the level number…, but that's still too far from my knowledge of regex to combine them.

Reply With Quote
  #2  
Old October 15th, 2012, 05:31 AM
Jacques3 Jacques3 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 57 Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level)Jacques3 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 10 h 6 m 14 sec
Reputation Power: 11
Hi,

Wow. I've seen regexes misused a lot for all kinds of things (like parsing XML), but this one takes it to a new level.

No offense, but regexes are not made for doing math. Simply search for numbers and leave it to your application to check if they're consecutive.

Reply With Quote
  #3  
Old October 17th, 2012, 06:42 PM
sergiozambrano sergiozambrano is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 16 sergiozambrano Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 7 m 50 sec
Reputation Power: 0
Certainty gives answers, uncertainty opinions.

Quote:
Originally Posted by Jacques3
Hi,

No offense, but regexes are not made for doing math. Simply search for numbers and leave it to your application to check if they're consecutive.


No offense, but that is what the PS was for.

Regardless of "being possible" with other methods, it NEEDS to be done in this way (through an existing plugin that performs regex search/replace from wordpress admin panel)

Any trick yo could imagine will be welcome along with your advice/opinion. A single "It's not possible" or "I don't know" is preferred, because even knowing it's DEFINITELY not possible is more useful than just questioning my application.

So… I'll asume you are not confident (nor have explored enough) to know with certainty that at least "it's not possible", and I'll add ( to prevent others to believe I've been taken care of): Anyone?

Reply With Quote
  #4  
Old October 17th, 2012, 07:22 PM
requinix's Avatar
requinix requinix is online now
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,873 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 5 Days 7 h 50 m 35 sec
Reputation Power: 8977
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 sergiozambrano
Regardless of "being possible" with other methods, it NEEDS to be done in this way (through an existing plugin that performs regex search/replace from wordpress admin panel)

Just because you need it done a certain way doesn't somehow make it possible.

Unless you can write some code of some kind somewhere, regular expressions cannot do this. You'd have to pare down the problem quite a bit before this would be possible, and even then the closest thing I can think of is so ridiculously complex (writing an HTML parser would be a walk in the park, comparatively) that I'd say it's not humanly possible.

Reply With Quote
  #5  
Old October 17th, 2012, 09: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: 203 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 16 h 10 sec
Reputation Power: 41
Quote:
I need to match consecutive numbers, and repeat the same piece of regex as long as they keep incrementing, and what would really reduce my expression, 250+ characters long already! (or rather make it more elegant) would be to:
be able to use the result from one capture group in another expression later
or
to get the current iteration number and match other expressions against

Post some input examples and what you want the output to be like examples.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Get recursion number or use result of group in later expression?

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