Python-Regular Expressions implement the calculator function and python-Regular Expressions
Requirements:
The user enters an operation expression and the terminal displays the calculation result.
Code:
1 #! /Usr/bin/env/python3 2 #-*-coding: UTF-8-*-3 4 "the user inputs the computation expression, show the calculation
Regular expressions, also known as pattern expressions, have a very complete set of syntax systems that can write patterns, providing a flexible and intuitive method of string processing. Regular expressions can be used to match, find, replace and split strings by constructi
Here are some examples of regular expressions that you might encounter:
/^\[\t]*$/"^\[\t]*$" matches a blank line.
/\d{2}-\d{5}/"\d{2}-\d{5}" verifies that an ID number consists of a 2-bit character, a hyphen, and a 5-digit number.
/The following table is a complete list of metacharacters and its behavior in the context of regular
"$" symbol, and the last line is represented. For example:
Sed-n ' 3p ' datafilePrint only the third line
Displays only the contents of the file for the specified row range, for example: # View only rows 100th through NO. 200 of a fileSed-n ' 100,200p ' Mysql_slow_query.log
Addresses are comma-delimited, the addresses that need to be processed are the ranges between the two lines, including these two lines. Scopes can be represented by numbers,
must be exactly two digits long. For example, "\ x41" matches "". "\ X041" is equivalent to "\ x04" "1. ASCII code can be used in regular expressions.
\Num
MatchNum,NumIs a positive integer. To capture matched reverse references. For example, "(.) \ 1" matches two consecutive identical characters.
\N
Identifies an octal escape code or a reverse reference. If \NAt leastNCapture sub-
underscores16. ^[/w-]+ (/.[ /w-]+) *@[/w-]+ (/.[ /w-]+) +$//matching email address17. ^[a-za-z]+://Matching (/w+ (-/w+) *) (/. ( /w+ (-/w+) *) * (/?/s*)? $//matching URL18. Matching regular expressions for Chinese characters: [/U4E00-/U9FA5]19. Match Double-byte characters (including Chinese characters): [^/x00-/xff]20. Application: Computes the length of the string (a double-byte character length meter 2,
Analysis of lastIndex and pre-query and indexof Regular Expressions in Regular Expressions
Write the following output in sequence.
var reg1 = /a/;var reg2 = /a/g;console.log(reg1.test('abcabc')); // trueconsole.log(reg1.test('abcabc')); // trueconsole.log(reg1.test('abcabc')); // trueconsole.log(reg1.test('abcabc')); /
PHP and EditPlus Regular expressions remove blank lines, editplus regular expressions
To remove a blank line inside a string:Copy the Code code as follows:$str = Preg_replace ("/(\s*?\r?\n\s*?) +/"," \ n ", $str);Remove all empty lines, including interior and tail:Copy the Code code as follows:$str = Preg_replace ('
I thought I was not particularly proficient in regular expressions, but there was no problem with the basic usage. But recently encountered a problem or let me stretched, thanks to Nango guidance.
Let's start with a general understanding of regular expressions.
Metacharacters
. Any character
^ Beginning of line
$ line
Extract video addresses from webpages using regular expressions. Extract video addresses using regular expressions.
// Extract the video address from the webpage using a regular expression // obtain a page address, get the page html, and then use the
Use regular expressions to replace strings and Server Regular Expressions in SQL server
Create a regular expression replacement function and use the OLE object. The following is the function code:
[SQL]View plain copy
-- If yes, delete the original function.
IF OBJECT_ID
).
For example:/apple (,) sorange1/match "Apple, orange, cherry, peach." In the ' Apple, Orange ', here is a more complete example.
Note: If the number in the left parenthesis is smaller than the number specified in N, then N takes a row of octal escape as a description.
Character Ooctal and Xhex
Meaning: Here the ooctal is a octal escape value, and Xhex is a hexadecimal escape value that allows ASCII code to be embedded in a regular expression
Att
"*" metacharacter specifies that its leading character must appear zero or multiple times in the target object,
And "?" Metacharacter specifies that the leading object must appear zero or once consecutively in the target object.
1/jim {2, 6 }/2 The above regular expression specifies that the character m can appear 2-6 times consecutively in the matching object. Therefore, the above regular expression can
\w match only Chinese, numbers, letters, for the Chinese people, only match the English will often use, see
Copy Code code as follows:
Matching regular expressions for Chinese characters: [\U4E00-\U9FA5]
Maybe you also need to match double-byte characters, and Chinese is also double-byte characters
Copy Code code as follows:
Match Double-byte characters (including Chinese characters)
Regular expressions: Matching in column values (wildcard matching whole column) 1 basic character matching
SELECT Prod_nameFrom ProductsWHERE prod_name REGEXP ' 1000 'Order BY Prod_name;
SELECT Prod_nameFrom ProductsWHERE prod_name REGEXP '. 000 'Order BY Prod_name;. is a special character in the regular expression language that represents matching any one charac
Use of Regular Expressions in PHP in Lesson 9, regular expressions in PHPToday's content1. Regular Expression2. mathematical functions3. Date Functions4. handle errorsRegular Expression:1. Pattern Modifier2. Five common functionsAnother
In the previous article we introduced JavaScript regular expressions and string regexp and string (a), and this article continues to share relevant content.
Objective
I think that in the process of learning a programming language, strings, arrays, containers are very important parts, in order to improve the efficiency of programming, I usually to the strings, arrays and containers for in-depth learning, d
Regular Expressions for JS password Strength Verification (simple and easy to use) and js Regular Expressions
I have been working on a pass project recently. In the registration module, the password strength (low and medium) needs to be displayed when I enter the password ). Today, I will share with you the results. Th
Introduction to regular expressions \ w metacharacters, regular expressions
Regular Expression \ w metacharacters:
The \ w metacharacters are used to match word characters. They are equivalent to "[a-zA-Z0-9]".Syntax structure:
Constructor method:
New RegExp ("\ w ")
Me
Verification of JS Regular Expressions and JS Regular Expressions
// Determine whether the input content is empty function IsNull () {var str = document. getElementById ('str '). value. trim (); if (str. length = 0) {alert ('Sorry, the text box cannot be blank or blank! '); // Change the "text box" to the attribute nam
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.