Tuesday, September 28, 2010

Half an hour to teach you learn regular expressions


Must have a lot of people have headaches on a regular expression. Today, I am in my understanding, with some articles online, hoping to use ordinary people can understand the expression. Come and share learning experiences.

Opening, still have to talk about the ^ and $ that they were used to match the beginning and end of the string, the following are examples of

"^ The": there must be the beginning of "The" string;
"Of despair $": the end must be "of despair" in the string;

Then,
"^ Abc $": that is demanded by abc abc at the beginning and end of the string, in fact, only matches abc
"Notice": matches a string that contains notice

You can see that if you do not use our two characters (the last example), that mode (regular expressions) can be tested in the string anywhere, you do not lock into either side of him

Then, talk about''*'',''+'', and''?'',

They can be used to indicate the number of occurrences of a character or sequence. They said:
"Zero or more" equivalent to (0,)
"One or more" equivalent to (1,),
"Zero or one." Equivalent to (0,1), here are some examples:

"Ab *": and ab (0,) synonymous, matching with a beginning, followed by 0 or N can take a b a string ("a", "ab", "abbb", etc.);
"Ab +": and ab (1,) synonymous, ibid article like, but there is at least one b ("ab", "abbb", etc..);
"Ab?": And ab (0,1) synonymous, can not, or only one b;
"A? B + $": matches a 0 or a combined more than one b-terminated string.

Points,''*'',''+'', and''?'' simply ahead of it that character.

You can also brace which limits the number of characters appear, such as

"Ab (2)": requests a later must be used with two b (Not One Less) ("abb");
"Ab (2,)": requirements must be behind a two or more b (such as "abb", "abbbb", etc..);
"Ab (3,5)": can be requested a behind 2-5 b ("abbb", "abbbb", or "abbbbb").

Now we must put parentheses in a few characters, such as:
"A (bc) *": matches a followed by 0 or a "bc";
"A (bc) (1,5)": 1-5 "bc."

There is also a character''鈹?#39;', equivalent to OR operation:

"Hi 鈹?hello": matches with "hi" or "hello" string;
"(B 鈹?cd) ef": match with "bef" or "cdef" string;
"(A 鈹?b) * c": This match contains a number (including 0) a or b, followed by a string c;

A point (''.'') can represent all the single characters, not including the "n"

If, to match including the "n" including all the individual characters, how do?
By the way, with''[n.]''this pattern.

"A. [0-9]": one a plus one character plus a number from 0 to 9
"^. (3) $": any characters at the end of the three.

The content enclosed in brackets matches only a single character

"[Ab]": matches a single a or b (and "a 鈹?b" the same);
"[Ad]": matches the''a''to''d''of a single character (and "a 鈹?b 鈹?c 鈹?d" are "[abcd]" the same effect); general we all with [a-zA-Z] to specify the character as a case in English
"^ [A-zA-Z]": matches a string beginning with uppercase and lowercase letters
"[0-9]%": match with a string of the form x%
", [A-zA-Z0-9] $": matches a comma plus a string of numbers or letters at the end of

You can also put you do not want to quest for the characters listed in the brackets, you only need to use''^'' inside brackets in the total as at the beginning of "% [^ a-zA-Z]%" matches with the two percent No. There is a non-letter string.

Highlights: ^ used in brackets at the beginning of time, it means rule out the characters in parentheses

For PHP to explain, you have added in front of these characters and some of the characters escape'''',.

Do not forget that the characters in the brackets which are exceptions to this rule the road - in the brackets which all the special characters, including (''''), will lose their special properties "[*+?{}.] "matches a string containing these characters.

Also, as regx manual tells us: "If the list contains'']'', best to list it as the first character (possibly with the''^'' back). Where it''- '', the best place it in front or end face, or a second or a range of end point [ad-0-9] the middle '-' will be effective.

Read the example above, you are (n, m) should understand it. Should be noted that, n and m can be negative integers, and n is always less than m. Thus, to match at least n times and the maximum matching m times. such as "p (1,5)" will match "pvpppppp" in the first five p

Talk to at the beginning of the following

b book that he is used to match a word boundary, that is ... such as''veb'', can match the love in the ve not match there very ve

Just above the b B and the opposite. I do not cite the example of

Well, we have to make a application:

How to build a model to match the quantity of input

Build a matching model to check whether the information entered, said money for a number. We think that the amount of money there are four ways: "10000.00" and "10,000.00", or no fractional part, "10000" and "10,000". Now let's start building that matches the pattern:

^ [1-9] [0-9] * $

This is the variable must be non-0 digit. But this also means that a single "0" also can not test. The following is the solution:
^ (0 鈹?[1-9] [0-9] *) $

"Only 0 to 0 at the beginning and not the number of matching", we can also allow a minus sign before the figures:
^ (0 鈹?-? [1-9] [0-9] *) $

That is: "0 or 1 to 0 at the beginning and may have a negative sign in front of the figure." Okay, now let us do so strict, allowing for 0 at the beginning. Now let us give up a negative sign, as we said When money does not need to use. We now specify the model used to match the fractional part:
^ [0-9 ]+(.[ 0-9 ]+)?$

This implies that the string must have at least matched by an Arabic numeral at the beginning. But note that in the above model "10." Does not match, only "10" and "10.2" can. (You know why right)

^ [0-9 ]+(.[ 0-9] (2))? $

We specified above must have two decimal places behind the decimal point. If you think this is too harsh, you can change:
^ [0-9 ]+(.[ 0-9] (1,2))? $

This will allow one or two behind the decimal point character. Now we add to increase the readability of the comma (every three), we can be said:
^ [0-9] (1,3) (, [0-9] (3 })*(.[ 0-9] (1,2))? $

Do not forget''+'' can be''*'' alternative if you want to allow empty string is entered, then (why?). Do not forget the anti-diagonal''string in the php error may occur (very common error).

Now, we can confirm that a string, we now have removed all the commas str_replace (",", "", $ money) and then type as in the double and then we can do through his mathematical the.

Encore:

Construct a regular expression check email

In a complete email address has three parts:
1. User name (all in''@'' left),
2 .''@'',
3. Server name (the part that is left).
User name can contain uppercase and lowercase letters digits, periods (''.''), minus (''-''), and underlined (''_''). server name is consistent with this rule, of course, the next except crossed.

Now, the beginning and the end user name can not be the end. Server as well. There you can not have two consecutive periods at least one character between them, well now we look at how to write a user name match pattern:

^ [_a-ZA-Z0-9-] + $

Now allow the existence of a full stop. We put it together:
^ [_a-ZA-Z0-9-]+(.[_ a-zA-Z0-9-]+)*$

The above would mean: "to regulate at least one character (except.) At the beginning, followed by 0 or more a point to the beginning of the string."

Simplification that we can use eregi () replaced ereg (). Eregi () are case insensitive, we do not need to specify the two range "a-z" and "A-Z" - only need to specify a on it:
^ [_a-Z0-9-]+(.[_ a-z0-9-]+)*$

Behind the server name is the same, but remove the underscore:
^ [A-z0-9-]+(.[ a-z0-9-]+)*$

Good. Now just use "@" to connect two parts:
^ [_a-Z0-9-]+(.[_ a-z0-9-]+)*@[ a-z0-9-]+(.[ a-z0-9-]+)*$

This is the complete email authentication matches the pattern, and only need to call
eregi ('^[_ a-z0-9-]+(.[_ a-z0-9-]+)*@[ a-z0-9-]+(.[ a-z0-9-]+)*$ ', $ eamil)
Whether email can be a

Other uses of regular expressions

Extract string
ereg () and eregi () has a feature that allows users to extract regular expressions as part of the string, for example, we would like from the path / URL extracted file name - the following code is what you need:
ereg ("([^ \ /]*)$", $ pathOrUrl, $ regs);
echo $ regs [1];

Advanced substitution
ereg_replace () and eregi_replace () is also very useful: If we want all the intervals are replaced with a comma minus sign:
ereg_replace ("[nrt] +", ",", trim ($ str));

Finally, I check the other strings EMAIL regular expression to see the article for you to analyze.
"^[-!#$%&''*+ \ ./0-9 =? AZ ^ _ `az {|}~]+''.''@''.''[-!#$ %&''*+ \ / 0-9 =? AZ ^ _ `az {|}~]+.''.''[-!#$%&''*+ \ ./0-9 = ? AZ ^ _ `az {|}~]+$"
If you can easily read, that the purpose of this article reached.






相关链接:



News About Languages Education



A flash drive to buy the real Experience



AVI To MOV



Authorware make poetry OF the sentence



Jinshan valve management upgrade erp sweet taste



In October 2007 The Sixth New York International Outsourcing Exhibition



3GP to FLV



REVIEWS Covert Surveillance



On the memory LEAK (1)



DV to AVI



Graphic Editors introduction



Clever and FTP PERMISSIONS under control related forums



Expert Vehicles - Screen Savers



JSF To Pass Parameters Via URL



Pocket Baidu claims 10 MILLION downloads have been pushed Android version has expired



BI The New World: Semi-finals Games, Who The Winner?



3% discount notebook supplier return profits BEHIND



Tuesday, September 14, 2010

IDC how to charge only reasonable



The Internet is an innovative, industry, and it can change each to the customer, to the end consumers more benefits. Data center industry as Internet infrastructure builders and operators, one of the pace of its more representative and forward-looking. Wind at the end of Qingping, pricing model indicates the transition bandwidth of our previous views on the need to rewrite.

Actual use of resources to pay

We face from everyone I start charging for telecommunications, which in fact has been a matter of common concern in recent years, the hot, like the way the phone charges, mobile and fixed phones, etc. to determine the minimum billing unit of time, such as that the use of fixed phones, why are they only say 1 minute, or even only a few seconds, 3 minutes have to pay the money? That which must exist irrational factors.

In fact, unreasonableness not only seen in the voice communications, data communications, there is the same, or even more serious. Bandwidth of the hire, the common unit charges generally 2M, 10M and 100M of three grades, which means that one would like to use the 15M bandwidth, customers will have to buy 100M. Although many consumers a few dollars, dozens of dollars unreasonable tariff and the cry for justice, but in data communications, the user has paid much more should not pay the cost, however, no doubt sound, this is really a bit strange. As the century, vice president of Internet Data Center Co., Ltd Chang Chun by analogy, the fixed bandwidth rental costs as phone users than the number of actual telephone call payments, but must choose to play 100 or 1000 phone; in order to prevent possible The telephone service was terminated embarrassing situation, he might have to buy their own business needs above telephone number, and to pay a lot of money. So why not use the basis of his actual phone number of charges?

Width does not equal fast

At present, the telecommunications industry with CKS surging tide of change. Advances in technology to promote the traditional circuit-switched to packet-switched transfer of pace. This change is comprehensive, it also brings the telecommunications business model and fee adjustments. We are now facing some of the irrational factors that are actually content with the old rates of new business caused by incompatible way.

The current telecom operators, especially Internet data center operators usually 2M, 10M and 100M bandwidth unit receives a fixed fee per month. These figures actually refer to the server from the client to the operator connected with the backbone network bandwidth between routers, rather than any visitor can enjoy bandwidth. Some customers may have felt was not proportional to the bandwidth and access speed, this is because the Internet is a shared network, numerous nodes, the network users to access a company's Web site actually been a lot of packet nodes , any node of the delay will allow users to find the site to respond fast enough, and this delay is beyond the control of a single operator's. From this perspective, the width does not mean fast, simple bandwidth charges to the user or data center in terms of the perspective of both the existence of certain one-sidedness.

Long overdue attempt

In fact in the world, at all levels of telecom operators are trying to use the new pricing model to give customers more transparency, more flexibility and more fair price, while leading a more rational purchase and use of bandwidth. But in China, due to the lag of awareness, technical power shortages and restrictions 缃戠粶 hardware environment, pricing model of transition Cai just Kaishi, Qizhongdongzuo of a century faster Internet network Shuju 涓績. They have begun to recommend their clients use the new pricing model, that is not simply buy bandwidth based on customer receives a fixed monthly fee, but by the Shiji of data traffic charges. This requires a considerable foundation.

First, from the technical point of view, charging a fixed monthly fee simple and direct, while data traffic charges by means of the continuous flow of customers to monitor and measure, technical requirements greatly increased. But the point is still worth the trouble, because that their customers can have a clear understanding traffic, but also can know Liuliang time and space distribution of the business development and market strategy adjustment of great significance. Century is connected with MRTG (Multiple Router Traffic Grapher) software for data traffic statistics. It is a 5-minute sampling interval, and then generate a detailed chart, intuitive and clear. Some of the world famous Internet data center operators, such as AboveNet and Exodus, adopted the software for monitoring and billing. Century, while Internet use MRTG statistics also adopted the principle of the customer 5% of the peak traffic out of the baseline beyond the billing, so customers need not worry about traffic accidents caused by large transient rise in the price.

In addition to technical means to ensure network resources are also affected by the charging method in which one of the determinants. A data center operator may own the hardware environment is very advanced, fiber optic cabling used in all interior rooms, routers and switches is also the top, but it also depends on the final speed of access and backbone networks, export-bandwidth Internet connection. It's a bit like Beijing's Third Ring Road, the road itself is very good condition, light on the fast track is the four-looked, but because of the narrow exit, poor traffic flow, affecting road capacity. This network data center may prefer a fixed rate pricing model, because it can not guarantee that the final speed of access. The Century Internet bandwidth resources fairly obvious advantages, it is first approved by Ministry of Information Industry access to the national Internet Exchange (NAP) of professional IDC company, broadband access NAP with nine state-owned public peering backbone ( Public Peering). It also with China Telecom, China Unicom and China Netcom signed a commercial peering (Private Peering) agreement and the agreement with ChinaNet Internet bandwidth 922M, is by far and ChinaNet peer networking connectivity and bandwidth of the IDC's largest companies buy .

Responsibility for the data center

Chang Chun-century Internet that the Internet does not exist a real exclusive bandwidth, everything is shared, and customers are most concerned about is speed rather than "exclusive" or "shared" bandwidth. Exclusive distribution of the bandwidth speed is only one way to ensure it can not effectively control costs. Another way to non-full-bandwidth. With the highway, for example, enjoys a bandwidth as the four loop are assigned to a customer to use, although the speed is faster, but the customer has to pay the huge independent expenditures occupy four loop. In the new model, all customers can use the Fourth Ring Road, the customer traffic over the network once the peak capacity of 60% of the road will be widened. Thus, not only the customer can be assured the server response time and reduce costs.

"The new pricing model enable service providers to assume more responsibility," Chang Chun said, "It also advocates user scientific, planned use of network bandwidth, according to the actual amount paid, less pay less, use more, pay. For customers, the payment will be according to actual use of savings, and to more efficient use of bandwidth. "







相关链接:



windows media player m4v



wmv PS3



WINDOWS 7 rmvb



Ps3 Rmvb