Php regular expression foresight and post-analysis applications

Source: Internet
Author: User
Tags php regular expression expression engine
Php regular lookup and postfix analysis applications often need to deal with thousands of log entries for log analysis. in order to find data in a specific mode in a large amount of data, many complex regular expressions are often required. For example, if the cited log file does not contain entries of a specific string, find entries that do not start with a specific string, and so on .? Regular expressions have the concepts of Lookahead and Lookbehind. These two terms are very useful for php regular lookup and analysis.

For log analysis, you often need to deal with thousands of log entries. to find data in a specific mode in a large amount of data, you often need to write many complex regular expressions. For example, if a log file does not contain entries of a specific string, you can find entries that do not start with a specific string.

?

Regular expressions have the concepts of Lookahead and Lookbehind. These two terms describe the matching behavior of the regular expression engine. Note that the front and back of the regular expression are a little different from what we generally understand. For a piece of text, we generally call the direction at the beginning of the text as "front", and the end of the text as "back ". HoweverFor the regular expression engine, because it is parsed from the text header to the tail (you can use the regular expression option to control the resolution direction), for the tail direction of the text, it is called the "front ", at this time, the regex engine has not moved to that part, but the direction of the text header is called "back", because the regex engine has passed through that part.

?

When a regular expression matches a character, you can preview the text that has not been parsed to see if it meets/does not match the matching mode, check whether the matching mode is met or not in the text that has been matched by the regular expression engine. This is also calledAffirmative match and negative match.

Modern Advanced Regular expression engines generally support forward looking, which is not widely supported by postcare. Therefore, we use forward looking with a negative expression to meet our needs.

?

The first group does not match anything, but the second group matches the entire string. Let's take a look at the regular expression. In fact, when the regex engine is resolved to the domain, the forward-looking work in Area B has been started. At this time, it is found that the match is successful when the region is Null ――. * null characters are allowed to be matched, and the forward-looking conditions are met. the domain is followed by a "2009" string instead of a robots. Therefore, all entries are successfully matched during the entire matching process.

?

Set .*? Forward expression

?

?

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.