Home > DeveloperSection > Interviews > How we list which characters we DON'T want ?How to use backslash character

Posted on    June-08-2013 8:21 AM

 ASP.Net ASP.Net 
 1 Answer(s)
  1367  View(s)
Rate this:

Andrew Deniel
Andrew Deniel

Total Post:5

Posted on    June-08-2013 12:00 AM

We can list which characters we DON'T want so just use a '^' as the first symbol in a bracket expression
(i.e., "%[^a-zA-Z]%" matches a string with a character that is not a letter between two percent signs).
"^[a-zA-Z]": a string that starts with a letter;
"[0-9]%": a string that has a single digit before a percent sign;
",[a-zA-Z0-9]$": a string that ends in a comma followed by an alphanumeric character. 

In order to be taken literally, you must escape the characters "^.[$()|*+?{\" with a backslash ('\'), as they have special meaning. On top of that, you must escape the backslash character itself in PHP3 strings, so, for instance, the regular expression "(\$|¥)[0-9]+" would have the function call: ereg("(\\$|¥)[0-9]+", $str)

Don't want to miss updates? Please click the below button!

Follow MindStick