In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use regular expressions in VS2008 to find and replace, with 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.
Regular expressions are a concise and flexible representation of finding and replacing text patterns. When you perform a Quick find, find in File, Quick replace, or replace in File operation in the find and replace window, you can use a set of dedicated regular expressions in the find what and replace with fields of the window.
To enable regular expressions, expand find options in the find and replace window, select use, and then select regular expressions. The triangle expression Builder buttons next to the find what and replace with fields become available. Click this button to display a list of the most commonly used regular expressions. When you click a regular expression on the list, it inserts the location of the cursor in the find what or replace with field. When you click complete character list at the bottom of the expression Builder, a help topic is displayed. The topic content covers all the regular expressions recognized by the Visual Studio find and replace function. You can copy the regular expression in the topic and paste it into the find what or replace with field.
The regular expressions that can be used in find what and replace with have many grammatical differences from valid regular expressions in .NET Framework programming. For example, in the find and replace window, curly braces {} are used for the replacement of marked expressions: change the doesn't to does not each time it appears, you should use the lookup expression {does} ntreast and the replacement expression\ 1 not.
Regular expressions for find and replace
The regular expressions that are often used in the expression Builder are as follows.
Expression.
Grammar
Description
Example
Any character
.
Matches any character except a line break.
A.O matches "aro" in "around" and "abo" in "about", but not "acro" in "across".
Zero OR
Multiple
*
Does not match the previous expression, or matches multiple times, and generates all possible matches.
An ab matches "b" in "bat" and "ab" in "about".
E.roome matches the word "enterprise".
An or
More.
+
Matches at least one search term of the previous expression.
Ac+ matches words that contain the letter "a" and at least one letter "c", such as "race" and "ace".
A. matches the word "access".
Line head
^
Anchor the matching string to the beginning of the line.
^ car matches the word "car" only if it appears as the first set of characters in the editor line.
End of line
$
Anchors the matching string to the end of the line.
End$ matches the word "end" only if it appears as the last set of characters that may be at the end of the line in the editor.
Prefix
Matches words that end with the alphabetic combination "ss", such as "across" and "loss".
Newline character
\ n
Matches newline characters independent of the operating system. In the replace expression, insert a newline character.
End\ nBegin matches the words "End" and "Begin" only if "End" is the last string on the line and "Begin" is the first string on the next line.
In the "replace" expression, Begin\ nEnd replaces the word "End" in the first line with "Begin", inserts a newline character, and then replaces the word "Begin" with the word "End".
Any character in the set
[]
Matches any character in []. To specify a range of characters, list the starting and ending characters separated by a dash (-), such as [amurz].
Be [NMurt] matches "bet" in "between", "ben" in "beneath" and "bes" in "beside", but does not match "bel" in "below".
Any character that is not in the set
[^.]
Matches any characters that are not specified in the character set that follows ^.
Be [^ NMurt] matches "bef" in "before", "beh" in "behind" and "bel" in "below", but does not match "ben" in "beneath".
Or
| |
Matches the expression before or after the OR symbol (|). It is most commonly used in groups.
(sponge | mud) bath matches "sponge bath" and "mud bath".
Escape character
\
Matches the characters after the backslash (\) literally. This allows you to find characters used in regular expression representations, such as {and ^.
\ ^ search for ^ characters.
Tagged expressions (or backreferences)
{}
Use the text in parentheses to identify the location of the text to be replaced.
{does} ntreast identifies the text before the replacement in the replacement string,\ 1 each item that occurs when the not change occurs.
Cactus + Identifier
: i
An abbreviated form of the expression ([a murzAmurz $] [a-zA-Z0-9 colors $] *).
Matches any possible Cmax Candle + identifier.
Quoted string
: q
The shorthand form of the expression (("[^"] * ") | ('[^'] *')) that matches all characters enclosed in double or single quotation marks, as well as the quotation marks themselves.
: Q matches Test reference and Test reference, but does not match "'t" in "can't".
Spaces or tabs
: b
Matches spaces or tabs.
Public:bInterface matches the phrase "Public Interface" in the text.
Integer number
: z
An abbreviated form of the expression ([0-9] +) that matches any combination of numeric characters.
Match any integer, such as "1", "234", "56", and so on.
The list of all valid regular expressions in the find and replace operations is longer than the list that can be displayed in the expression Builder. Although the following regular expressions are not displayed in the expression Builder, you can use them in the find what or replace with fields.
Expression.
Grammar
Description
Example
At least,
Zero OR
More.
@
Matches 0 or more search terms of the previous expression, and matches as few characters as possible.
E.@ matches "ente" and "erprise" in "enterprise" but does not match the complete word "enterprise".
At least,
An or
More.
#
Matches one or more search terms of the previous expression and matches as few characters as possible.
Ac# matches words that contain the letter "a" and at least one letter "c", such as "ace".
A. matches "acces" in the word "access".
Repetition
N times
^ n
Matches the n occurrences of the previous expression.
[0-9] ^ 4 matches any sequence of 4 digits.
Grouping
()
Allows you to combine a set of expressions together. If you want to search for two different expressions in one operation, you can use grouping expressions to combine the two expressions.
If you want to search for (- [amurz] [1-3] or-[0-9] [amurz]), you should combine the two expressions as follows: ([amurz] [1-3]) | (- [0-9] [aMuz]).
The nth
With mark
Text of
\ n
In the find or replace expression, indicates the text matched by the nth marked expression, where n is a number from 1 to 9.
In the replace expression,\ 0 inserts the entire matching text.
If you search for a {[0-9]} and replace it with\ 1, all search terms followed by "a" are replaced by the following numbers. For example, "A1" is replaced by "1", and similarly, "a2" is replaced by "2".
Right align field
\ (w.cn)
In the replace expression, align the nth marked expression in the field to the right at least w characters wide.
If you search for a {[0-9]} and replace it with\ (10 an 1), the search term for "SQL" is replaced by an integer and aligned to the right by 10 spaces.
Left-aligned field
\ (- w.w.n)
In the replace expression, align the nth marked expression in the field to the left at least w characters wide.
If you search for a {[0-9]} and replace it with\ (- 10 an 1), "SQL" is replaced by an integer and aligned to the left by 10 spaces.
Prohibited
Match
~ (X)
Suppresses matching when X appears at this position in the expression.
Real~ (ity) matches "real" in "realty" and "really", but not "real" in "reality".
Letter
Figures
Character
: a
Match the expression ([a-zA-Z0-9]).
Match any alphanumeric characters, such as "a", "A", "w", "W", "5", and so on.
Letter
Character
: c
Match the expression ([a-zA-Z]).
Match any alphabetic characters, such as "a", "A", "w", "W", and so on.
Decimal number
: d
Match the expression ([0-9]).
Match any number, such as "4" and "6".
Hexadecimal number
: h
Match the expression ([0-9a-fA-F] +).
Matches any hexadecimal number, such as "1A", "ef", and "007".
Rational number
: n
Match expression (([0-9] +. [0-9] *) | ([0-9] *. [0-9] +) | ([0-9] +)).
Match any rational number, such as "2007", "1.0", and" .9 ".
Alphabetic string
: w
Match the expression ([a-zA-Z] +).
Matches any string that contains only alphabetic characters.
Escape character
\ e
Unicode Utility 001B.
Matches the escape control character.
Bell
\ g
Unicode Utility 0007.
Matches the "Bell" control character.
Backspace
\ h
Unicode Utility 0008.
Matches the "Backspace" control character.
Tab character
\ t
Unicode Utility 0009.
Tabs match.
Unicode character
\ xxxxxxxmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Matches the character given by the Unicode value, where # is a hexadecimal number. You can specify characters outside the basic multilingual plane (that is, a surrogate) with ISO 10646 code points or two Unicode code points that provide values for surrogate pairs.
\ u0065 matches the character "e".
The following table lists the two-letter acronyms used to specify the common categories listed in the Unicode character properties database. You can use these acronyms in the regular expression character set. For example, the expression [: Nd:Nl:No] matches any type of number.
Expression.
Grammar
Description
capital
: Lu
Matches any capital letter. For example:
: Luhe matches "The" but not "the".
Lowercase letters
: Ll
Matches any lowercase letter. For example:
: Llhe matches "the" but not "The".
The first capital letter
: Lt
Matches characters that combine uppercase and lowercase letters, such as Nj and Dz.
Modifier letter
: Lm
Matches letters or punctuation marks, such as commas, cross accents, and double apostrophes, to indicate modifications to the previous letter.
Other letters
: Lo
Match other letters, such as the Gothic letter ahsa.
Decimal number
: Nd
Matches decimal numbers, such as 0-9, and their double-byte equivalents.
Alphanumeric
: Nl
Matches alphanumeric characters, such as Roman numerals and ideographic zero.
Other numbers
: No
Match other numbers, such as the old italic number one.
Start punctuation
: Ps
Matches the opening punctuation marks, such as the left square bracket and the left brace.
Ending punctuation mark
: Pe
Matches closing punctuation marks, such as closing brackets and closing curly braces.
Left quotation mark
: Pi
Matches the left double quotation marks.
Closing quotation mark
: Pf
Matches single quotation marks and right double quotes.
Dash
: Pd
Matches the dash mark.
Connection symbol
: Pc
Matches the underscore mark.
Other punctuation marks
: Po
Match (,),?, ",!, @, #,%, &, *,\, (:), (;), 'and /.
White space separator
: Zs
Match blank.
Line delimiter
: Zl
Matches the Unicode character Ubun2028.
Paragraph separator
: Zp
Matches the Unicode character Ubun2029.
No interval mark
: Mn
There is no interval mark to match.
Combination marker
: Mc
Matches the combined tag.
Closed mark
: Me
Matches the closure tag.
Mathematical symbol
: Sm
Match +, =, ~, |,
< 和 >.
Currency symbol
: Sc
Matches $and other currency symbols.
Modifier symbol
: Sk
Match modifier symbols, such as uplift, mute, and long.
Other symbols
: So
Matches other symbols, such as copyright symbols, paragraph marks, and degree symbols.
Other control
: Cc
Matches Unicode control characters such as TAB and NEWLINE.
Other formats
: Cf
Format control characters, such as two-way control characters.
Surrogate
: Cs
Matches half of the surrogate pair.
Other private use
: Co
Matches any character in the private area.
Other unassigned characters
: Cn
Matches characters that are not mapped to Unicode characters.
In addition to the standard Unicode character attributes, you can specify the following attributes as part of the character set.
Expression.
Grammar
Description
Alpha
: Al
Matches any character.
For example,: Alhe matches the words "The", "then", "reached" and so on.
Numerical value
: Nu
Match any number or number.
Punctuation
: Pu
Match any punctuation mark, such as?, @,', and so on.
Blank
: Wh
Matches all types of white space, such as printing and ideographic white space.
Two-way
: Bi
Matches characters written from right to left, such as Arabic and Hebrew.
Korean
: Ha
Match Hangul and combine Hangul alphabet.
Hiragana
: Hi
Matches hiragana characters.
Katakana
: Ka
Matches katakana characters.
Ideographic characters / Kanji / Kanji
: Id
Match ideographic characters, such as Kanji and Kanji.
Wildcards for find and replace
The following wildcards are available in the expression Builder.
Expression.
Grammar
Description
Any single character
?
Matches any character.
Any number
#
Match any number. For example, matching includes a number of 7 followed by another number, such as 71, but does not include 17.
Characters that are not in the character set
[!]
Matches any character that is not specified in the character set.
Escape character
\
Matches the characters after the backslash (\) literally. This allows you to find the characters used in wildcard representations, such as * and #.
One or more characters
*
Matches zero or more characters. For example, new* matches any text that includes "new", such as newfile.txt.
Character set
[]
Matches any character specified in the character set.
Thank you for reading this article carefully. I hope the article "how to use regular expressions to find and replace in VS2008" 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: 219
*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.