Re: Regular Expressions?
| From: | Jason Caldwell | Date: | Fri, 20 Apr 2001 06:49:17 +0000 |
| Subject: | Re: Regular Expressions? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-49507@lists.php.net to get a copy of this message | ||
Thats what the book said too... but what I'm confused about is the word
START and END -- at what point does the start end, and the end begin? If
you look at my example below
aaa.a! <-- matched
>
> aaa.! <-- no match
>
> after I put the $ on the end
>
> aaa.a! <-- no match
>
> aaa.aa32 <-- match...
It looks like the ^ and $ are actually needed it you want the expression to
work correctly *at all*.
Thanks.
Jason
""Jack Dempsey"" <dempsejn@georgetown.edu> wrote in message
news:NEBBKBGAMLPMIDAJEALPEEOFCGAA.dempsejn@georgetown.edu...
> if you put ^ at the start of your regexp, that means you want the start of
> the string to match your expression...$ is used for the end of the
string...
>
> -jack
>
> -----Original Message-----
> From: Jason Caldwell [mailto:jason@thinkingman.org]
> Sent: Friday, April 20, 2001 2:41 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] Regular Expressions?
>
>
> I'm a little lost as to the exact function of the following:
>
> ^ and $
>
> I noticed in the example below... that when I added the $ to the end of
the
> expression, I wasn't able anymore to put a non-alphanumeric character in
the
> end, for example (without the $)
>
> I was able to enter the following and get a 'match'
>
> aaa.a! <-- matched
>
> aaa.! <-- no match
>
> after I put the $ on the end
>
> aaa.a! <-- no match
>
> aaa.aa32 <-- match...
>
> So, am I to understand that the ^ and $ are used to tell the expression
that
> it *must* match what the expression expects? I guess why I'm so confused
is
> because -- I thought when you create an expression, that it must match the
> parameters of that expression... then what are the ^ $ for?? It's like to
> create an expression, but it truly won't work unless you have it turned on
> with ^ $ characters.
>
> Thanks.
> Jason
>
>
>
> "Brian Clark" <brianj@fusionwerks.com> wrote in message
> news:92203389127.20010420015151@fusionwerks.com...
> > Hi Jason,
> >
> > @ 1:43:19 AM on 4/20/2001, Jason Caldwell wrote:
> >
> > ...
> > > I want to match any of the following:
> >
> > > 1.1 or a.a
> >
> > > or 1111.1111 or aaaa.aaaa <-- any number of digits (0-9) or alpha
> (a-z)
> > > on either side of the dot.
> >
> > > if(eregi("^([0-9][a-z]\.[0-9][a-z]", $myArray[x]))
> >
> > Your parentheses are slightly wrong.
> >
> > if(
> > eregi(
> > "^
> > (
> > /* unmatched parens */
> >
> > [0-9][a-z]
> > /* only matches one digit or character */
> >
> > \.
> > /* matches period */
> >
> > [0-9][a-z]
> > /* only matches one digit or character */
> > ",
> > $myArray[x]
> > )
> > /* syntax error :) */
> > )
> >
> > > Is this correct? I think I'm missing something.
> >
> > You want something like this:
> >
> > <?php
> >
> > /* eregi("^([[:alnum:]]+\.[[:alnum:]]+)", $myArray[x]) */
> >
> > $string = 'aaa.aaa';
> > $string_2 = 'aaaaaa';
> >
> > print(eregi("^([[:alnum:]]+\.[[:alnum:]]+)", $string) ? 'matched' :
> > 'no
> match');
> > print(eregi("^([[:alnum:]]+\.[[:alnum:]]+)", $string_2) ? 'matched' :
'no
> match');
> >
> > ?>
> >
> > > Thanks.
> > > Jason
> >
> > -Brian
> > --
> > PGP is spoken here: 0xE4D0C7C8
> > Please, DO NOT carbon copy me on list replies.
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>