• PHP Help General Help
  • [RESOLVED] Where does Manual tell about using caret "^", scalar "$" in eregi pattern matching?

Hello;

Can anybody tell me where in the PHP Manual I can find documentation that tells the proper way to use the caret "" and the scalar "$" characters with the eregi function?

Below is a code statement that I got from a book written by Larry Ullman. It was Larry Ullman's first book. The book is entitled "PHP For The Worldwide Web."

if (!eregi("^([[:alnum:]]|_|\.|-){3,15}$", $UserName)){
exit('The username can only have letters, numbers, underscores, dashes, and periods. It can contain a maximum of 15 characters.');	
	}

The above statement will permit the $UserName to contain only letters, numbers, underscores, dashes, and periods. The length must be between 3 and 15 characters.

For my own peace of mind I'm trying to figure out where Larry Ullman found how to use the caret "" and the scalar "$" in the statement above so I don't have to take his word for it.

The documentation in the PHP Manual for the eregi function uses the caret and the scalar just like Ullman. You can find code statements under the "User Contributed Notes" section of the page.
http://us.php.net/manual/en/function.eregi.php
But the Manual on that page (or any other page that I can find) does not make a single mention of the use of the caret and the scalar in the pattern matching process.

I would appreciate any information.

Thanks.

    Firstly, I suggest switching to use the PCRE functions instead. The PHP Manual's PCRE pattern syntax page describes the use of the ^ and $ assert start/end of subject meta-characters.

      laserlight;

      Thanks for the suggestion. I appreciate the information.

        You're welcome 🙂
        To quote bradgrafelman:
        Don't forget to mark this thread resolved (if it is).

          laserlight is definitely right - the PCRE functions are much better/faster than the ereg* ones.

          Once you switch over to PCRE, you'll find that your patterns need a little tweaking. First, your patterns need delimiters, with a forward slash being the most common (e.g. '/(([:alnum:]))...$/'). Second, there is no pregi_match() for case-insensitive matching. Instead, you need to add the 'i' modifier after your last delimiter.

          For more information about PCRE such as the different modifiers, syntax, etc., I've found this tutorial to be very helpful.

            Write a Reply...