php - Preg match a string to find all encounters of -> using regular expressions -


i'm having small technical difficulty regular expression, i'm trying @ string, let's have string:

$string = "error->400"; 

and string:

$string = "error->debug->warning"; 

as example, i'm trying preg_match() returns true on instances of -> within it.

this attempt don't understand why doesn't work:

preg_match("/^[->]*$/", $string); 

is there general rule custom characters i'm missing?

thanks.

right now, ^[->]*$ matches number of "-" or ">" characters, beginning end. must use group, not character class, , anchors not necessary. use check if "->" present in $string:

 preg_match("/(->)/", $string); 

have @ example.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -