|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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/ Is the proper way to use brackets like: Code:
$text =~ /$word(s)/i; or is there a more correct way? Thanks in advance Jizster |
|
#2
|
|||
|
|||
|
you can simply bracket out the vaiable name as follows:
$text =~ /${word}s/i; |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
Thanks folks!
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Probably really easy question about regex... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|