RegexBuddy 4 and regular expressions

				RegexBuddy 4和正则表达式 
开发工具与关键技术:vs RegexDemo
作者:赵纯雨
班级:1804
撰写时间:2019.5.2

What is a regular expression, regular expression: It is also called regular expression, and its English name is Regular Expression.
When writing code, regular expressions are usually abbreviated as: regex, regexp or, RE. You must remember that in the future The abbreviation of regular expression often appears in the code, as long as you see it, you know that this is a shorthand for regular expression.
It is also commonly used to retrieve and replace texts that match certain or certain patterns. In layman's terms, regular expressions are a tool for text matching.
For example, such as:
him, history, high, hi, if I want to match hi in this string, I can directly use the regular expression hi. This regular expression is the most direct and simplest one. All hi objects are directly matched in the object. As shown in the figure below, you will see two colors in the matching objects below, that is, all hi objects that are matched, as shown in the figure:
Insert picture description here
if in the string Among them, there will be many characters containing hi in words. If you want to match hi exactly, you will need a special character \b, which is a special character specified by regular expressions. We will use it It is called a metacharacter. It can only match one position at the beginning or end of a common word, that is, at the boundary of a word. Although usually English words are separated by spaces or punctuation or newlines, \b does not match these Any of the word separators, just like mobile phone navigation, you output where you want to go in the search interface, then enter the text, and then click search, and then the navigation system will search according to the instructions you give Match to an accurate location. Then if I want to match hi in this string, I need to use \b:
Insert picture description here
as shown in the figure above, the corresponding character is matched in the matched object, indicating that it can only match one position.
In regular expressions, there is a special character. We call it metacharacters. In regular expressions, we define a lot of metacharacters. Here are some common metacharacters and their antonyms:.
(English status The period under) It is to match any character except the newline character.
\w (lower case) matches numbers or letters or underscores or Chinese characters. \W (uppercase) matches any letter that is not a number, letter, underscore, or Chinese character \s (lowercase) matches any blank character (tab, space, enter) \S (uppercase) matches any character that is not a blank character. \d (lowercase) matches numbers \D (uppercase) matches any character that is not a number \b (lowercase) matches the beginning or end of a word \B (uppercase) matches that is not the beginning or end of a word ^ matches the beginning or end of a string The end of the
string Character definition:
"\": If you want to find the meta character itself, for example, if you find \w, if \w\d\s\b appears in my string, I want to match them So, how do you match? \w is a meta character. If you type \w directly, you will not be able to match it. The matched numbers are all numbers, letters, underscores, and Chinese characters, which must match \w If it is itself, add a \ directly in front, for example:
if you directly match \w, you can't match this metacharacter, example: Insert picture description here
as shown in the figure above, if you match like this, it matches The objects are numbers, letters, underscores, and Chinese characters. You cannot match \w itself. If you want to match the meta-character itself, add one in front! Insert the picture description here
so that you can match the \w itself, this slash \ means escape.
There is also a type of qualifier, qualifier, what is a qualifier, that is, within its own limited scope, cannot be exceeded, the
commonly used qualifier:

  • Repeat zero or more times
  • Repeat one or more times
    ? Repeat zero times or once
    {n} Repeat n times
    {n,} Repeat n times or with multiple
    {n,m} Repeat n to m times
    to see if there is any pattern above, for example, I match a \d, It matches 25 objects. I want to match three digits at a time. What should I do? \d It is the number of matching units. There are 25 objects in total. It is matched one by one, and I want to go all at once. Match three digits,
    Insert picture description here
    and some people with obsessive-compulsive disorder want to match all of them. Then, I use {n,m} to repeat n to m times in the match, as shown in the figure:
    Insert picture description here
    its A matching range is greater than or equal to 2 and less than or equal to 6.

Guess you like

Origin blog.csdn.net/weixin_44540773/article/details/89972972