Jump to content

Anchor two times in a pattern

- - - - -

  • Please log in to reply
1 reply to this topic

#1
dadli

dadli

    Newbie

  • Members
  • PipPip
  • 12 posts
Hello programesr. My questions is about regex.
I want create the pattern, Which correspond to three symbol a, or tree symbol b
this is my code:

$str = 'aaa';

if (preg_match("#^aaa$|^bbb$#",$str)) {

	echo 'yes';

}


in this code is anchor two times, this is working code , but it is interesting to me: this variant is correctament?
That is: To insert in a pattern of an anchor two (or more) times, it is justified?
Thanks

#2
dadli

dadli

    Newbie

  • Members
  • PipPip
  • 12 posts
This is answer form my questions:
$str = 'aaa'; 

if (preg_match("#^(aaa|bbb)$#",$str)) { 

    echo 'yes'; 

}  

Thanks all, Question are not so actual




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users