In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you why to learn regular expressions, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
What is a regular expression?
Regular expression, also known as regular representation, conventional representation (English: Regular Expression, often abbreviated to regex, regexp or RE in code), is a concept in computer science. Regular expressions use a single string to describe and match a series of strings that conform to a syntactic rule. It is useful in almost all kinds of computer programming languages. It can be divided into ordinary regular expressions, extended regular expressions and advanced regular expressions. Common regular expressions are commonly used in linux shell, and advanced regular expression syntax specifications are basically evolved from perl. At present, all common programming languages (php,perl,python,java,c#) support advanced regular expressions.
Why should we learn regular expressions?
Regular expressions in high-level programming languages are almost developed from the perl language, so the syntax is almost consistent. You've learned a regular expression language. It can be used in almost all programming languages. Like, I know the sql syntax, and the back-end mysql,mssql is almost universal. This is also one reason why we need to learn regular expressions well, versatility. Another reason is the powerful text matching function of regular expressions. A lot of text matching processing is really difficult to do without regular expressions. Such as: from a string, read out the mobile phone number format, if we use the string search, need to do a loop, need to write judgment. It is estimated that it takes a lot of code and development time. If you use regular expressions, just one line of code will be fine. Match all pairs: html tags, if you want to do this, we find it very complex, to deal with the hierarchy, to match the tags. Generally speaking, the same person may not be able to finish it in a few hours. If you use regular expressions, it will only take a few minutes.
Regular expression string format
Now that we know the importance of regular expressions, generality. Then we can learn about common formats. A general regular expression consists of a string consisting of ordinary characters + special characters (metacharacters). For example, it matches the beginning of "ab, followed by the numeric string"ab\ d +", where ab is an ordinary character,\ d represents a 0-9 number, and + indicates that the preceding character can appear once or more. Haha, it looks really easy!
Regular expressions, whether normal or extended or advanced regular expressions. The differences may be somewhat different in terms of special characters. Many special characters can be combined to form a new set of matching rules. Let's not go too deep here. We usually only need to know its common metacharacters. Basically, common regular expressions can be written.
The following metacharacters are common to javascript regular expressions:
Character description\ marks the next character as a special character, or a literal character, or a backward reference, or an octal escape character. For example,'n 'matches the character "n".' \ n' matches a newline character. The sequence'\ 'matches "\" and "(" matches "(". ^ matches the starting position of the input string. If the Multiline property of the RegExp object is set, ^ also matches the position after'\ n'or'\ r'. $matches the end of the input string. If the Multiline property of the RegExp object is set, $also matches the position before'\ n'or'\ r'. * matches the previous subexpression zero or more times. For example, zo* can match "z" and "zoo". * is equivalent to {0,}. + matches the previous subexpression one or more times. For example, 'zo+' can match "zo" and "zoo", but not "z". + is equivalent to {1,}. ? Matches the previous subexpression zero or once. For example, "do (es)?" Can match "do" in "do" or "does". ? It is equivalent to {0jue 1}. {n} n is a non-negative integer. Match the determined n times. For example,'o {2} 'does not match the' o'in 'Bob', but does match the two o in 'food'. {n,} n is a non-negative integer. Match at least n times. For example,'o {2,} 'does not match' o'in 'Bob', but does match all o in 'foooood'. O {1,}'is equivalent to 'oasis'. O {0,}'is equivalent to 'oval'. {n ·m} m} m and n are non-negative integers, where n
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.