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
https://forums.phpfreaks.com/topic/166453-solved-whats-wrong-with-my-expression/
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.  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.