Jump to content

[SOLVED] What's wrong with my expression?


elis

Recommended Posts

I'm trying to figure this regex stuff out, so I've consulted a few resources how to properly write one -- but as my script is no longer working, I suspect I have it wrong.

 

I'm trying to make sure a variable contains the correct allowed values which are alphanumeric and a single underscore followed by the word "useruid": i.e. W2kyK8Etr_useruid

 

So I've written this:

<?php $allow = "^[a-zA-Z0-9]_{1}useruid$";

if(eregi($allow,$_COOKIE[$genkey."_useruid"])) {
$cleanuid = $_COOKIE[$genkey."_useruid"];
}

?>

 

But it isn't working because I am new to this regex thing and probably messed something up. Could someone spot my mistake?

 

Link to comment
Share on other sites

If you are still using ereg, I would consider learning preg [part of pcre] instead, as ereg (part of POSIX) is depreciated as of php 5.3 and will no longer be included within the core as of version 6.

 

Here are some additional resources to help get you started in pcre:

 

http://www.regular-expressions.info/

http://weblogtoolscollection.com/regex/regex.php

http://www.phpfreaks.com/forums/index.php/topic,127902.0.html

http://www.phpfreaks.com/tutorial/regular-expressions-part1---basic-syntax

 

These should be more than enough to help get you started.  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.