Regular expression Basics in php
Posted by Raj
Regular expression Basics in php:
In this article ,i will show how to use regular expressions in php.
\char escape char
. Any single character
[chars] One of following chars
[^chars] None of following chars
text1|text2 text1 or text2
? 0 or 1 of the preceding text
* 0 or N of the preceding text (hungry)
+ 1 or N of the preceding text
Example: (.+)\.html? matches test.htm and test.html
(text) Grouping of text
Example: ^(.*)\.html foo.php?bar=$1
^ Start of line anchor
$ End of line anchor
Example: ^test(.*) matches test and test1 but not ttest
(.*)1$ matches a1 and b1, but not test
In this article ,i will show how to use regular expressions in php.
\char escape char
. Any single character
[chars] One of following chars
[^chars] None of following chars
text1|text2 text1 or text2
? 0 or 1 of the preceding text
* 0 or N of the preceding text (hungry)
+ 1 or N of the preceding text
Example: (.+)\.html? matches test.htm and test.html
(text) Grouping of text
Example: ^(.*)\.html foo.php?bar=$1
^ Start of line anchor
$ End of line anchor
Example: ^test(.*) matches test and test1 but not ttest
(.*)1$ matches a1 and b1, but not test
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
PHP,
PHP interview questions and answers,
regex,
Regular Expressions,
Regular Expressions PHP Tutorial
.You can leave a response, or trackback from your own site.