Jump to content


Photo

*SOLVED* I have been learning regular expressions


  • Please log in to reply
No replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 April 2006 - 03:53 PM

Sorry for any spellings wrong.

I have been learning regular exspressions i thort i shall shere my madness.
Good luck.




<?
echo"<br><br><br>";

//This is true dog is in the sentence.

$dog="my dog is lucky";
if(ereg("dog",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>

<?
echo"<br><br><br>";

//This is not true, the word dog not at the begining

$dog="my dog is lucky";
if(ereg("^dog",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";

//This is not true, ereg is case sencetive Dog does not match

$dog="my Dog is lucky";
if(ereg("^dog",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";

//This is true, Dog is capital letter and is at the begging

$dog="Dog is lucky";
if(ereg("^Dog",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>

<?
echo"<br><br><br>";
 
//This is true, eregi is not case sencetive dog does match even tho Dog upper case

$dog="my Dog is lucky";
if(eregi("dog",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";
 
//This is not true becouse the end $ symbol sees dog at the end

$dog="my dog is lucky";
if(ereg("dog$",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>

<?
echo"<br><br><br>";
 
//This is true becouse dog$ is at the end

$dog="this is my dog";
if(ereg("dog$",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>



<?
echo"<br><br><br>";
 
//This is not true becouse dosent see ^dog$ at the begiging and end exact

$dog="this is my dog";
if(ereg("^dog$",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>



<?
echo"<br><br><br>";
 
//This is true becouse ^dog$ at the begining and end exzact

$dog="dog";
if(ereg("^dog$",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";
 
//This is true there are three ddd in the string 

$dog="dddog is mine";
if(ereg("d{3}",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";
 
//This is not true there are not three ddd in the string

$dog="ddog is mine";
if(ereg("d{3}",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>




<?
echo"<br><br><br>";
 
//This is true looking for three ddd or more

$dog="dddog is mine";
if(ereg("d{3,}",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";
 
//This is not true looking for 3ddd and maximum of five ddddd

$dog="dddddddog is mine";
if(ereg("d{3,5}",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>



<?
echo"<br><br><br>";
 
//This is true there is a d and afther the d there is a ooooooooo more then 2

$dog="dooooooooooog is mine";
if(ereg("d(o){2,}",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";
 
//This is false there is a d but the o issint more then 2

$dog="dog is mine";
if(ereg("d(o){2,}",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";
 
//This is true there is a d and a and o and this sign* means 0 or more

$dog="dog is mine";
if(ereg("d(o)*",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";
 
//This is not true there is a d but no s the+ sign wants one or more

$dog="dog is mine";
if(ereg("d(s)+",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>

<?
echo"<br><br><br>";
 
//This is true there is a d and afther that there is a o but also the+ wants to see 1 or more

$dog="dooog is mine";
if(ereg("d(o)+",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>



<?
echo"<br><br><br>";
 
//This is true becouse lucky is in the ereg but using the | meaning or in regular exsperisons

$dog="my dog name is lucky and we live in a house";
if(ereg("lucky|also|money",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>

<?
echo"<br><br><br>";
 
//This is not true no words matched in regular exsperisons using |or

$dog="my dog name is lucky and we live in a house";
if(ereg("be|also|money",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>




<?
echo"<br><br><br>";
 
//This is true but we are useing the brackets() to enclose the or| and also the remaining ie at the end

$dog="my dogie name is lucky  and we live in a house";
if(ereg("(dog|also|money)ie",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>



<?
echo"<br><br><br>";
 
//This is true but we are useing the brackets() to enclose the or| and also the remaining wildcard.e at the end the wild 

//card acts as the i

$dog="my dogie name is lucky  and we live in a house";
if(ereg("(dog|also|money).e",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>

<?
echo"<br><br><br>";
 
//This is true but we are useing the brackets() to enclose the or| and also the remaining wildcard.e at the end the wild 

//card acts as the i and adding the+ will use more then 1. wildcard

$dog="my doggie name is lucky  and we live in a house";
if(ereg("(dog|also|money).+e",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>

<?
echo"<br><br><br>";
 
//^.{47}$ this tell the ereg that begging^ .wildcard any charecter {47} amount of chareter and $end so if the string is 47 

//chareters long true.

$dog="my doggie name is lucky  and we live in a house";
if(ereg("^.{47}$",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";
 // This is true using[] brackets and og at the end

$dog="dog";
if(ereg("[dtnk]og",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";

//This is not true becouse ereg see d+o

$dog="d+o";
if(ereg("d+o",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>


<?
echo"<br><br><br>";

//This is true becouse the backslash\ makes d and o correct using a back slash

$dog="d+o";
if(ereg("d\+o",$dog)) {
echo" your dog is lucky";
}else{
echo"your dog not lucky";
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users