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 November 6th, 2008, 10:56 AM
flhu flhu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 55 flhu User rank is Sergeant Major (2000 - 5000 Reputation Level)flhu User rank is Sergeant Major (2000 - 5000 Reputation Level)flhu User rank is Sergeant Major (2000 - 5000 Reputation Level)flhu User rank is Sergeant Major (2000 - 5000 Reputation Level)flhu User rank is Sergeant Major (2000 - 5000 Reputation Level)flhu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 12 m 16 sec
Reputation Power: 29
S/(.*)/$1 something/gi; "double dipping"

I have some user variables (a high-level user with knowledge of regex and admin privileges, so it doesn't need to be sanitized) going into a substitution which is equivalent to:
Code:
$i = "TEST";
$i =~ s/(.*)/$1 Blah/gi;
print $i;
And it outputs:
Quote:
TEST Blah Blah
(it's doing it twice) Ok, so I know that the issue is the global. The problem is that sometimes I would want the same code to handle something like:
Code:
$i = "TEST THING is the BEST THING";
$i =~ s/(.*?) THING/$1 Blah/gi;
print $i;
which it correctly outputs:
Quote:
TEST Blah is the BEST Blah
Do I have to make some sort of conditional testing for the veracity of the wildcard with different multiple substitution syntaxes (or additional variable input allowing the user to turn on/off the global flag, which is what I'll probably end up doing), or is there a simpler way?

Thanks
__________________
If you can read this, I'm probably very confused and disorientated.

Reply With Quote
  #2  
Old November 12th, 2008, 08:46 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,811 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 19 h 13 m 52 sec
Reputation Power: 6112
Actually I believe you're running into a weirdness with regular expressions. You're using .* which is causing the replace to be evaluated twice. Try using .+ and .+? in your two expressions, respectively.

-Dan
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
  #3  
Old November 18th, 2008, 11:35 AM
flhu flhu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 55 flhu User rank is Sergeant Major (2000 - 5000 Reputation Level)flhu User rank is Sergeant Major (2000 - 5000 Reputation Level)flhu User rank is Sergeant Major (2000 - 5000 Reputation Level)flhu User rank is Sergeant Major (2000 - 5000 Reputation Level)flhu User rank is Sergeant Major (2000 - 5000 Reputation Level)flhu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 12 m 16 sec
Reputation Power: 29
Thanks for the response... I did end up just adding a separate user variable (checkbox) that turns on/off the global flag, and it works fine.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > S/(.*)/$1 something/gi; "double dipping"

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