In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what is VB.NET regular expression, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
1. What is a VB.NET regular expression
Basically, a regular expression is a pattern used to describe a certain amount of text. Regex stands for RegularExpress. This article will be used to represent a specific regular expression. A piece of text is the most basic pattern, simply matching the same text.
two。 Different VB.NET regular expression engines
The regular expression engine is a kind of software that can handle regular expressions. In general, the engine is part of a larger application. In the software world, different regular expressions are not compatible. This tutorial will focus on Perl5-type engines because they are the most widely used engines. At the same time, we will also mention some differences from other engines. Many modern engines are similar, but not exactly the same. For example, the .NET regular library, the JDK regular package.
3. Text symbol
The most basic regular expression consists of a single literal symbol. Such as
< >Which matches the character "a" that appears * * times in the string Such as the string "Jackisaboy". The "a" after "J" will be matched. The second "a" will not be matched. Regular expressions can also match the second "a", which must be when you tell the regular expression engine to start searching at * times. In the text editor, you can use "find next". In the programming language, there will be a function that allows you to continue to search backwards from the location of the previous match. Similarly, it matches the "cat" in "Aboutcatsanddogs". This is tantamount to telling the VB.NET regular expression engine to find one, followed by a
< >Oh, one more. Note that the regular expression engine is case-sensitive by default. Unless you tell the engine to ignore case, it will not match "Cat".
Special characters for text characters, 11 characters are reserved for special purposes. They are: []\ ^ $. These special characters are also called metacharacters. If you want to use these characters as text characters in regular expressions, you need to escape them with a backslash "\". For example, if you want to match "1-1-2", the correct expression is
< >It is important to note that
< >Is also a valid regular expression. But it will not match "1 # 1 # 2", but will match "111 # 2" in "123 # 111 # 234". Because the "+" here means a special meaning (repeated one or more times). In programming languages, it is important to note that some special characters are processed by the compiler and then passed to the regular engine. So regular expressions
< >Write "1\ + 1 # 2" in C++. To match "C:\ temp", you use regular expressions. In C++, the regular expression becomes "C:\ temp".
Non-displayable characters can use special character sequences to represent some non-displayable characters:
< >Stands for Tab (0x09)
< >Stands for carriage return (0x0D)
< >For the newline character (0x0A), note that the text file in Windows uses "\ r\ n" to end the line, while Unix uses "\ n".
The internal working mechanism of the 4.VB.NET regular expression engine
Knowing how the regular expression engine works helps you quickly understand why a regular expression doesn't work as you expect. There are two types of engines: text oriented (text-directed) engines and regular oriented (regex-directed) engines. JeffreyFriedl calls them DFA and NFA engines. This article is about regular-oriented engines. This is because some very useful features, such as "lazy" quantifiers (lazyquantifiers) and backreferences (backreferences), can only be implemented in regular-oriented engines. So it's not surprising that this kind of engine is the current engine. You can easily tell whether the engine you are using is text-oriented or regular-oriented. If backreferences or "lazy" quantifiers are implemented, you can be sure that the engine you are using is regular-oriented. You can do the following test: apply regular expressions to the string "regexnot". If the result of the match is regex, the engine is regular-oriented. If the result is regexnot, it is text-oriented. Because the regular-oriented engine is "urgent", it will be eager to show its work and report the matches it finds.
Regular-oriented engines always return the leftmost match-an important point to understand: even if it is possible to find a "better" match later, regular-oriented engines always return the leftmost match. When applied to "Hecapturedacatfishforhiscat", the engine first compared to "H" and failed. So the engine failed to compare it with "e". Until the fourth character matches "c".
< >Matches the fifth character. To the sixth character failed to match "p", also failed. The engine continues to re-check the match from the fifth character. Until the fifteenth character starts and matches the "cat" in "catfish", the regular expression engine eagerly returns * matches instead of looking for other better matches.
5. Character set
A character set is a set of characters enclosed by a square bracket "[]". Using the character set, you can tell the regular expression engine to match only one of the multiple characters. If you want to match an "a" or an "e", use the
< >. You can use matching gray or grey. This is especially useful when you are not sure whether the characters you are searching for are in American English or British English. Instead, graay or graey will not be matched. The order of the characters in the character set does not matter, and the result is the same. You can use the hyphen "-" to define a character range as the character set.
< >Matches a single number between 0 and 9. You can use more than one range.
< >Matches a single hexadecimal number and is case-insensitive. You can also combine scope definitions with individual character definitions.
< >Matches a hexadecimal number or letter X. Again, the order of character and range definitions has no effect on the result.
Some applications of the character set look for a word that may be misspelled, such as or. Find the identifier of the program language
< >. (* for repeating 0 or more times) find a C-style hexadecimal number
< >. (+ means repeat one or more times)
If the inverse character set is followed by an angle bracket "^" in the left square bracket "[", the character set will be inverted. The result is that the character set matches any characters that are not in square brackets. Unlike ".", the inverse character set can match the carriage return newline character. It is important to remember that the inverse character set must match one character.
< >It doesn't mean that it matches a Q with no u followed by it. It means that it matches a Q, followed by a character that is not u. So it does not match the Q in "Iraq", but matches the Q in "Iraqisacountry" and a space character. In fact, the space character is part of the match because it is a "character that is not u". If you just want to match a Q, provided that Q is followed by a character that is not u, we can solve it by looking forward as we will talk about later.
The metacharacters in the character set need to be noted that only 4 characters in the character set have a special meaning. They are: "]\ ^ -". "]" Represents the end of the character set definition; "\" represents escape; "^" represents inversion; and "-" represents range definition. Other common metacharacters are normal characters within the character set definition and do not need to be escaped. For example, to search for an asterisk * or plus +, you can use the
< >. Of course, if you escape the usual metacharacters, your regular expressions will also work well, but this will reduce readability. In the character set definition, in order to use the backslash "\" as a literal character rather than a special meaning character, you need to escape it with another backslash.
< >Will match a backslash and an X. "] ^ -" can be escaped with a backslash, or put them in a position where it is impossible to use their special meaning. We recommend the latter because it increases readability. For example, for the character "^", put it except after the left parenthesis "[", using the literal character meaning rather than the reverse meaning. Such as
< >Will match an x or ^.
< >Will match a "]" or "x".
< >Or
< >Will match a "-" or "x".
The abbreviation of a character set because some character sets are very commonly used, so there are some abbreviations.
< >Representative
< > < >Represents a word character. This varies depending on the implementation of the regular expression. Most of the word character sets implemented by regular expressions contain
< >.
< >Stands for "white character". This is also related to different implementations. In most implementations, space and Tab characters are included, as well as carriage return newline characters
< >. The abbreviated form of a character set can be used inside or outside square brackets.
< >Matches a white character followed by a number.
< >Matches a single white character or number.
< >Will match a hexadecimal number. Take the abbreviation of the inverse character set
< >=
< > < >=
< > < >=
< >Repetition of a character set if you repeat a character set with the "? * +" operator, you will repeat the entire character set. Not just the character it matches. Regular expression
< >Will match 837 and 222. If you just want to repeat the character that is matched, you can use a backward reference to achieve the goal. We'll talk about quoting back later.
Thank you for reading this article carefully. I hope the article "what is VB.NET regular expression" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.