Forum Moderators: coopster

Message Too Old, No Replies

perl regex

         

electricocean

12:25 am on Jun 9, 2006 (gmt 0)

10+ Year Member



I am not really understanding perl regex. I want to check if a string contains a dash or something. Could I use the perl regex using preg-replace to do this?

elictricocean

eelixduppy

2:29 am on Jun 9, 2006 (gmt 0)



Here is a thread on Regular Expressions [webmasterworld.com]. However, if you want to check to see if a string has a dash(-), then I would just use the string function, strpos [us2.php.net]. The code would then go something like this:

$text = "Here is-some text";
if(strpos($text,"-"))
{
echo "Dash found in string!";
}
else {
echo "Dash cannot be found in string.";
}

Good luck!

eelixduppy

10:56 am on Jun 9, 2006 (gmt 0)



Ooops.. My code has an error (I keep making this mistake). It should go like this:
$text = "Here is-some text";
if(strpos($text,"-")===FALSE)
{
echo "Dash cannot be found in string.";
}
else {
echo "Dash is found in string.";
}

Sorry about that.