Regular expression Example: Find another string in a string

Source: Internet
Author: User
Tags expression first string query regular expression
Regular | string <body>
<a href= "./" > Return list </a><br>
<form action= "<?echo $PHP _self;? > "method=" Post >
In <input type= "text" Name= "string" value= "<?echo $string;? > > Find <input type= "text" name= "query" value= "<?echo $query;? > "><br>
<input type= "Radio" Name= "where" value= "" <?if (!isset ($where) or $where = = "") echo "checked";? >> the second string can be at any position in the first string <br>
<input type= "Radio" Name= "where" value= "^" <?if (Isset ($where) and $where = = "^") echo "checked";? >> the first string starts with the second string <br>
<input type= "Radio" Name= "where" value= "$" <?if (Isset ($where) and $where = = "$") echo "checked";? >> the first string ends with the second string <br>
<input type= "checkbox" name= "case" value= "case" <?if (Isset ($case)) echo "checked";? >> Case Sensitive <br>
<input type= "Submit" value= "Query" >
</form>
?
if (Isset ($string) and Isset ($query) and $string <> "" and $query <> "") {
if (Isset ($case)) {
$func = "Ereg";
}
else{
$func = "Eregi";
}
Switch ($where) {
Case "^":
$query = "^". $query;
Break
Case "$":
$query. = "$";
Break
}
Eval ("\ $found = $func (\" $query \ ", \" $string \ ");
if ($found) {
echo "Find it! ";
}
else{
echo "Not Found! ";
}
}
?>
</body>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.