Home > Archive > PERL Beginners > February 2007 > how to match the '?' character?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to match the '?' character?
|
|
| dtown22@gmail.com 2007-02-21, 3:58 am |
| I am very new to perl, and I am trying to figure out how to match a ?,
but i cant seem to figure it out (unless I am doing something else
wrong, which is very possible). Here is my code:
foreach($newBody =~ m/$thread?/isg)
$thread contains a number, which i expect to be followed by a '?'
Basically I want to do something specific for each occurrence,
depending on what else is in the string
but for some reason, this loops more than it should.
If however, i do something like this:
$index = 0;
while($index != -1) {
$index = index($newBody, "$thread?", $index);
}
it loops the correct number of times.
any help is greatly appreciated.
| |
|
| You need to escape the '?' .. like /$thread\?/
- ani
dtown22@gmail.com wrote:
> I am very new to perl, and I am trying to figure out how to match a ?,
> but i cant seem to figure it out (unless I am doing something else
> wrong, which is very possible). Here is my code:
>
> foreach($newBody =~ m/$thread?/isg)
>
> $thread contains a number, which i expect to be followed by a '?'
>
> Basically I want to do something specific for each occurrence,
> depending on what else is in the string
>
> but for some reason, this loops more than it should.
>
> If however, i do something like this:
>
> $index = 0;
> while($index != -1) {
> $index = index($newBody, "$thread?", $index);
> }
>
> it loops the correct number of times.
>
> any help is greatly appreciated.
| |
| dtown22@gmail.com 2007-02-21, 6:59 pm |
| On Feb 21, 1:07 am, "Ani" <call.anir...@gmail.com> wrote:
> You need to escape the '?' .. like /$thread\?/
>
> - ani
>
I thought that might be the case, but I couldn't find any
documentation on special escape characters. Do you happen to know of a
good resource that lists them all?
| |
| Uri Guttman 2007-02-21, 6:59 pm |
| >>>>> "d" == dtown22 <dtown22@gmail.com> writes:
d> On Feb 21, 1:07 am, "Ani" <call.anir...@gmail.com> wrote:[color=darkred]
d> I thought that might be the case, but I couldn't find any
d> documentation on special escape characters. Do you happen to know of a
d> good resource that lists them all?
you obviously didn't read perldoc perlre. perl is very well
documented. if you need more basic regex stuff read perlrequick and
perlretut.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
|
|
|
|
|