Weekend Summary Regular Expressions (full text) _ Regular expressions

Source: Internet
Author: User
Tags class definition php regular expression prev

Hi

And the weekend, the result is no movie to see this week, just practice regular expression bar, warm hands

1, regular expressions-end of the article

---tool class development---

<?php * * PHP Regular Expression Tool class * Description: Regular expression matching, there are common regular expressions and allow users to customize the regular expression to match the/class regextool{//define common regular expressions, and array to store the private $validate =array (' Require ' => '/.+/', ' email ' => '/^\w+ ') ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$/', ' url ' => '/^http (s?): \ /\/(?: [A-za-z0-9-]+\.) +[a-za-z]{2,4} (?: [\/\?#][\/=\?%\ -&~ ' @[\]\ ': +!\.#\w]*)? $/', ' Currency ' => '/^\d+ ' (\.\d+)? $/', ' number ' => '/^\d+$/', ' Zip ' => '/^\d{6}$/', ' Integer ' => '/^[-\+]?\d+$/', ' Double ' => '/^[-\+]?\d+ (\.\d+)? $/', ' 中文版 ' => '/^[a-za-z]+$/', ' QQ ' => '/^\d
{5,11}$/', ' Mobile ' => '/^1 (3|4|5|7|8) \d{9}$/',); Define other properties private $returnMatchResult =false; Return type to judge private $fixMode =null; Modified mode private $matches =array ();
Store matching results private $isMatch =false; constructor, instantiated and passed in the default two parameter public function __construct ($returnMatchResult =false, $fixMode =null) {$this->
returnmatchresult= $returnMatchResult;
$this->fixmode= $fixMode;
///Judge return result type, matches or match ismatch for match result, and call return method Private function Regex ($pattern, $subject) {if (Array_key_exists (Strtolower ($pattern), $this->validate)) $pattern = $this->validate[$pattern]. $this-> Fixmode;
The correction mode is used as a matching regular expression $this->returnmatchresult?
Preg_match_all ($pattern, $subject, $this->matches): $this->ismatch=preg_match ($pattern, $subject) ===1;
return $this->getregexresult (); //Returns method Private Function Getregexresult () {if ($this->returnmatchresult) {return $this->matches;}
else{return $this->ismatch;}} Allow user-defined toggle return type Public Function Togglereturntype ($bool =null) {if empty ($bool)) {$this->returnmatchresult=! $this-
>returnMatchResult;
}else{$this->returnmatchresult=is_bool ($bool) $bool: (bool) $bool;}  The following is the data validation method public function Setfixmode ($fixMode) {$this->fixmode = $fixMode;} public Function Noempty ($STR) {return
$this->regex (' Require ', $str); Public Function Isemail ($email) {return $this->regex (' emails ', $email);} public Function IsMobile ($mobile) {return
$this->regex (' mobile ', $mobile); } public Function Check ($pattern, $subject) {return $this->regex ($pattern, $subject);} 

Instantiated for validation

<?php * * PHP Regular expression validation file///contains class definition file require_once ' regexTool.class.php ';
$regex =new Regextool (); $regex->setfixmode (' U ');
Set correction mode for lazy mode u $r = $regex->isemail (' asdfads@qq.com ');

Show ($R); Use the show function you've learned before * * description:php Regular expression function * * @name: Show * @description: Output Debug * @param $var: input data * @r eturn void * */function Show ($var =null) {if empty ($var)) {echo ' null ';} ElseIf (Is_array ($var) | | Is_object ($var)) {//array,object echo ' <pre> '; Print_r ($var); Echo ' </pre> ';}

else{//string,int,float. Echo $var;} ---Verify the form---that is using one of the methods HTML to write the file as follows <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >  

corresponding to the regcheck.php in the change

if (! $regex->noempty ($_post[' username ')) exit (' User name is empty ');

---imitation (cottage version) Smarty Simple template engine---

--Allows the program ape to separate the front-end back-end development

--Template engine works: Get the template source file, compile the template, output to the user (that is, contact the front and back, do "interface")

--mode unit: The total pattern, that is, the $pattern, the Thing in (), a custom atom, also becomes the mode element

In specific applications, Preg_match_all will match to two modes

Preg_match_all result is a two-dimensional array, where $matches[0][0] is the total mode

Other as child mode

--

2, JQuery

---introduction---

jquery is another good JavaScript library after prototype. It is lightweight JS library, it is compatible with CSS3, also compatible with various browsers (IE 6.0+, ff1.5+, Safari 2.0+, Opera 9.0+), jQuery2.0 and subsequent versions will no longer support the Ie6/7/8 browser. jquery makes it easier for users to process HTML (an application under the standard Universal Markup Language), events, animate, and easily provide Ajax interaction for the site. One of the big advantages of jquery is that it has a full documentation and a variety of applications that are detailed, as well as a number of mature plug-ins to choose from. jquery allows the user's HTML page to keep the code and HTML content separate, that is, you don't have to insert a bunch of JS into the HTML to invoke the command, just define the ID.
jquery is a browser-compatible JavaScript library with the core idea of write Less,do more (less written and more). jquery was released in January 2006 by John Resig of America in BarCamp, New York, attracting a number of JavaScript gurus from around the world to join the team led by Dave Methvin. Today, jquery has become the most popular JavaScript library, with more than 55% of the world's top 10,000 most visited sites using jquery.
jquery is free and open source, using the MIT license Agreement. jquery's syntax design makes it easier for developers to manipulate document objects, select DOM elements, animate effects, event handling, use Ajax, and other features. In addition, JQuery provides APIs for developers to write Plug-ins. Its modular use allows developers to easily develop powerful static or dynamic Web pages.

JQuery, as its name suggests, is JavaScript and query, which is a library of secondary JavaScript development. (picked from Baidu Encyclopedia)

--The environment constructs

Download the 1.9.0 stable version, save it locally, and then include it in JavaScript.
<script src= "Http://libs.baidu.com/jquery/1.9.0/jquery.js" type= "Text/javascript" ></script>

--Initial experience

jquery is the function of JS encapsulation, the formation of the library (private think it more conducive to the object)
Compared to the original JS, it is generally more convenient

<! DOCTYPE html>
 
 

Here $ () represents the element that matches a certain character characters

---base selector---

--#id选择器

<div id= "divtest" >div content </div>
<div id= "Default" ></div>
<script type= "text/" JavaScript ">
$" ("#default"). HTML ($ ("#divtest"). html ();//Display the contents of the ID number as the "divtest" element in the element with the ID number "default".
</script>

The basic use method is $ ("#id")

--element Selector

Depending on the name of the element, you can find the element and call the CSS (), attr (), and so on to set the action on the element you are taking.

--. class Selector

Select the element based on the name of the class, and other actions are similar

<div class= "Red" > Attention, come to my side </div>
<div class= "Green" > I'll take a rest. </div>
<script type= " Text/javascript ">
var $redHTML = $ (". Red "). html ();
$ (". Green"). HTML ($redHTML);
</script>

--* Selector

The parameter in the selector is a "*", there is no "#", there is no "." Resolution Because of the specificity of the selector, it is often used in combination with other elements to get all the child elements from other elements.

Practice has shown that, because the use of the * selector to get all the elements, so some browsers will be slow, this selector needs to be used with caution.

<form action= "#" >
<input id= "Button1" type= "button" value= "button"/> <input id= "Text1" type= "
Text "/> <input id= Radio1" type= "Radio"/> <input id= "
Checkbox1" type= "checkbox"/>
</ form>
<script type= "Text/javascript" >
$ ("form *"). attr ("Disabled", "true");
</script>

--sele1,sele2,selen Selector

Sometimes you need to select any number of specified elements, similar to the selection of the pen from a pencil box, you need to call the Sele1,sele2,selen selector, its calling format is as follows:

$ ("Sele1,sele2,selen")

Where the parameters sele1, sele2 to Selen are valid selectors, each selector is separated by a "," number, which can be the various type selectors mentioned previously, such as $ ("#id"), $ (". Class"), $ ("selector") selector, and so on.

<div class= "Red" > Choose me! I am red</div>
<div class= "Green" > Choose me! I'm green</div>
<div class= "Blue" > Choose me! This is blue</div>
<script type= "Text/javascript" >
$ (". Red,.green"). HTML ("Hi, we look beautiful!");
</script>

--ance desc Selector

In this section, we'll introduce the hierarchy selector.

In the actual application development, often is the multiple elements nesting together, forms the complex hierarchical relation, through the hierarchical selector, may quickly locate one level or many elements, ance desc selector is one of them, its invocation format is as follows:

$ ("ance desc")

where ance desc is two parameters separated by a space. The ance parameter (shorthand for the ancestor ancestor) represents the parent element, and the DESC parameter (abbreviated for descendant descendants) represents the descendant element, which includes child elements, grandchild elements, and so on. All two parameters can be obtained by selector. For example, family name "Div", the family for several generations, have a name in the "span", you can use this ance desc selector to the number of people to locate.

<div> Farm Family
<p>
<label></label>
</p>
<label></label>
</div>
<script type= "Text/javascript" >
$ ("div label"). CSS ("Background-color", "Blue");
</script>

--parent>child Selector

The parent > Child selector is smaller in scope than the ance desc selector described in the previous section, and its chosen target is a subset element, which is equivalent to a family of children, but does not include a grandchild, and its invocation format is as follows:

$ ("Parent > Child")

The child parameter gets elements that are children of the parent selector, and they represent a hierarchical relationship through the ">" symbol.

<div>
Farm Family
<p>
<label></label>
</p>
<label></label >
<label></label>
</div>
<label></label>
<script type= "text /javascript ">
$ (" Div>label "). CSS (" border "," solid 5px Red ");
</script>

--prev+next Selector

As the saying goes, "distant relatives than neighbors," and through the Prev + next selector can find the next element with the "prev" element, the format is as follows:

$ ("prev + next")

Where the parameter prev is any valid selector, the parameter "next" is another valid selector, and the "+" between them represents a hierarchical relationship between the top and bottom, that is, the next most immediate element of the "prev" element is returned by the "next" selector and only one element is returned.

<div>
Farm Family
<label></label>
<p></p>
<label></label>
<label></label>
</div>
<label></label>
<script type= "text/ JavaScript ">
$ (" P+label "). CSS (" Background-color "," Red ");
</script>

Note that next here is to enter the next classifier ID to look for, instead of directly entering next

--prev~siblings Selector

The same as the Prev + Next level selector described in the previous section, the prev ~ Siblings Selector is also an adjacent element after the Prev element is found, but the former only gets the first contiguous element, while the latter gets all the adjacent elements after the Prev element, which is called in the following format:

$ ("prev ~ siblings")

The relationship between the parameter prev and siblings is formed by the "~" sign, which indicates that the elements acquired by the siblings selector are sibling elements after the Prev element.

<div>
Farm Family
<label></label>
<p></p>
<label></label>
<label></label>
</div>
<label></label>
<script type= "text/ JavaScript ">
$ (" P~label "). CSS (" border "," solid 1px Red ");
$ ("P~label"). HTML ("We are all fans of Mr. P");
</script>

---filtering selector---

--:first/:last Filter Selector

In this chapter we introduce the filter selector, which is a match of elements based on a filter rule, which begins with a ":" Number, and is typically used to find a single element of a location in a collection element.

In jquery, what do you do if you want to get a 1th element in a set of identical label elements?

In the following sample code you may notice that we will use the

 $ ("Li:first")

Note: When writing, begin with the ":" Sign.

<div> change last line "apple" background color:</div>
<ol>
<li> grape </li>
<li> Banana </li>
<li> Orange </li>
<li> watermelon </li>
<li> Apple </li>
</ol>
< Script type= "Text/javascript" >
$ ("Li:last"). CSS ("Background-color", "Red");
</script>

--:eq (index) filter Selector

If you want to choose any of the tag elements flexibly from a set of tag element arrays, we can use the

: EQ (Index)

Where the argument index represents the index number (that is, an integer), it starts at 0, and if the value of index is 3, the 4th element is selected

<div> Change the middle line "grapes" background color:</div>
<ol>
<li> Orange </li>
<li> Banana </li >
<li> grape </li>
<li> Apple </li>
<li> watermelon </li>
</ol>
<script type= "Text/javascript" >
$ ("Li:eq (2)"). CSS ("Background-color", "#60F");
</script>

--:contains (text) filter Selector

As described in the previous section, the EQ (index) selector is more convenient when it comes to finding one or more elements in terms of the content of the text, and the function is to select all the elements that contain the specified string, as compared to the index lookup element. It is usually used in conjunction with other elements to get all the element objects that contain the contents of the "text" string. Where the parameter text represents the text in the page.

<div> change the background color containing the "jquery" character content:</div>
<ol>
<li> Powerful "jquery" </li>
<li > "JavaScript" is also very practical </li>
<li> "JQuery" front-end must learn </li>
<li> "Java" is a development language </li>
<li> Front End tool--"jQuery" </li>
</ol>
<script type= "Text/javascript" >
$ ("Li: Contains (' JQuery ') '). CSS ("Background", "green");
</script>

--:has (selector) filter Selector

In addition to using the included string content filtering elements described in the previous section, you can filter by using the included element names: The function of the has (selector) filter selector is to get all the elements in the selector that contain the specified element name, where the selector parameter is the containing element name. is the contained element.

<div> change the background color containing the "label" element:</div>
<ol>
<li><p> I'm Mr. P </p></li>
<li><label>l paper is me </label></li>
<li><p> I am also Mr. P </p></li>
<li><label> I am also l sister paper Oh </label></li>
Mr. <li><p>p is me oh </p></li >
</ol>
<script type= "Text/javascript" >
$ ("Li:has (' label ')"). CSS ("Background-color", "Blue");
</script>

--:hidden Filter Selector

: The function of the hidden filter selector is to obtain all elements that are not visible, including elements with the Type property value of hidden.

 
 

--:visible Filter Selector

In contrast to the: Hidden filter selector in the previous section: the Visible filtering selector gets all the visible elements, that is, if the display property value of the element is not set to none, then it is available through the selector.

 
 

--

The above content is about the Saturday summary of the regular expression (full article) of the full content, I hope you like.

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.