Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl 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 July 26th, 2001, 04:52 PM
jizster jizster is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 19 jizster User rank is Private First Class (20 - 50 Reputation Level)jizster User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 52 m 20 sec
Reputation Power: 0
Arrow Probably really easy question about regex...

I hope I don't get shouted at for asking a real simple question...

I don't really know what the proper terminology is in order to find the answer myself as I have taught myself perl over the last few months:

When using regex to match an expression containing a string eg:
Code:
$text =~ /$word/i;

what do you do if you want to match the same word but with an 's' on the end, how do you separate the 's' from the name of the variable?
As obviously this would look for the string called $words:
Code:
$text =~ /$words/i;

I assume you cannot escape the 's' like
Code:
/$word\s/
as this would try to match whitespace.
Is the proper way to use brackets like:
Code:
$text =~ /$word(s)/i;

or is there a more correct way?

Thanks in advance


Jizster

Reply With Quote
  #2  
Old July 27th, 2001, 05:23 AM
MattWilliams MattWilliams is offline
hmmmm...
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: UK
Posts: 37 MattWilliams User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
you can simply bracket out the vaiable name as follows:

$text =~ /${word}s/i;

Reply With Quote
  #3  
Old July 28th, 2001, 02:27 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
What you should really do:
Code:
  $var =~ /\Q$word\Es/i;


\Q .. something .. \E is treated as quoted text, so that $word can't be interpreted as a regex. the side benefit in your case is that you can then put an 's' after it all and it will be totally separate.
__________________
Jon Coulter
ledjon@ledjon.com

Reply With Quote
  #4  
Old July 29th, 2001, 11:28 AM
jizster jizster is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 19 jizster User rank is Private First Class (20 - 50 Reputation Level)jizster User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 52 m 20 sec
Reputation Power: 0
Thanks folks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Probably really easy question about regex...


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT