Discover python regular expression match example, include the articles, news, trends, analysis and practical advice about python regular expression match example on alibabacloud.com
This article describes how to use a regular expression to match and intercept the specified substring and deduplicate in Python. It involves the skills related to Python Regular Expression
The regular itself is a language:The regular expression uses a single string to describe, match a series of strings that conform to a certain syntactic rule, is very powerful in text processing, and is often used as a crawler to crawl specific content, and Python itself does
' verb ', but cannot match ' er ' in ' Never '.
\ n, \ t, et.
Matches a line break. Matches a tab character. such as
\1...\9
Matches the contents of the nth grouping.
\10
Matches the contents of the nth grouping, if it is matched. Otherwise, it refers to an expression of octal character code.
Modifier
modifier
Descriptio
This article uses two examples to compare and analyze the similarities and differences between using regular expressions to match a tag in js and c #. Let's take a look at it for your reference, which is helpful for a deep understanding of the use of regular expressions. Not much nonsense, all in the code, directly on
JS Code:
The Code is as follows:
that uses regular expressions to match IP addresses and convert IP addresses to corresponding values:Function IP2V (ip){Re =/(\ d +) \. (\ d +)/g // Regular Expression matching IP addressesIf (re. test (ip )){Return RegExp. $1 * Math. pow (255) + RegExp. $2 * Math. pow () + RegExp. $3 * + RegExp. $4*1}Else{Throw new E
-Numeric
\w
Match non-alphanumeric numbers
\s
Matches any whitespace character, equivalent to [\t\n\r\f].
\s
Match any non-null character
\d
Match any number, equivalent to [0-9].
\d
Match any non-numeric
\a
digit (because it follows the last expression, it must contain uppercase/lowercase letters, numbers, or special character sets [..
**************************************** ***************************************
// Check user name: only 1-30 strings starting with letters can be entered
/^ [A-Za-Z] {1, 30} $/
**************************************** ***************************************
// Password verification: only 6-20 letters, numbers, and under
escape Function of the Python Regular Expression module is independent. For example, to match a backslash character, you must write the parameter :'\\\\':
Python escapes the string \\\\ \\The re module obtains the passed \ and in
use '(? : '') ', Instead of just a pair of parentheses, it will produce an absolutely unexpected result.
For example, match the repeated 'AB' in the string'
>>> S = 'ababab abbabb aabaab'
>>> Re. findall (R' \ B (? : AB) + \ B ', S)
['Ababab']
If you only use a pair of parentheses, see what the result will be:
>>> Re. findall (R' \ B (AB) + \ B ', S)
['AB']
This is because if only one pair
1. Regular expressions?? Regular expressions provide the basis for advanced text pattern matching, extraction, and/or textual search and replace functions, and simply, regular expressions are strings of characters and special symbols. Python supports regular expressions thro
Python -- Regular Expression (5)
6. FAQsRegular Expressions are very powerful tools in applications, but sometimes they cannot be executed intuitively as you wish. This section describes some common problems with using regular expressions.
Certificate --------------------------------------------------------------------
In some cases of grasping and filtering, the advantage of regular expression regular expression is obvious.
For example, a string that resembles the following:
Copy Code code as follows:
Now you need to extract the URLs behind the href, [] within the dat
language (in Python) embedded in Python and implemented through the re module. The regular expression mode is compiled into a series of bytecode and then executed by the matching engine written in C.
# Import re module import re s = 'Nick jenny nice '# matching method (1) B = re.
This program is written because the campus network bulletin board from time to time there will be academic reports, lectures and other information published, but this kind of information is often published in the day before the lecture, so that many important messages lost. The bulletin board also publishes some content that is irrelevant to the students, such as the meeting of the Chairman of the trade union.The main difficulties encountered in the Chinese
A regular expression (regular expression) is a powerful logical expression used to match the form of text, and the RE module in Python provides support for
The first comparison system of learning regular expressions, this article in the PHP language as an example to learn.Basic conceptsRegular expressions = Ordinary characters (such as A-Z) + delimiters ( forward slash (/), hash sign (#), and Inverse (~)) + special characters (called metacharacters);Matching principleA simple description, usually starting with the string position 0, attempts to
that match regular expressions[0-9] {3,5} 9678A?b bA+b Aaaaab3) Location^ Starting position of the string$ end position of the stringThe regular expression matches the string example does not match the string^ab.*c$ ABEEC CABEEC
In the programming of the basic will use regular expression to deal with the data, then the following specific in PHP how to use it, this article through concrete examples, to explain the use of the PHP expression in the method.
Recently, using PHP to write an application, mainly the processing of regular expressions,
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.