📄 regexp.html
字号:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Tom Archer">
<TITLE>String - Table of Contents</TITLE>
<META Name="description" Content="Source code for CString extension">
<META Name="keywords" Content="SOURCE CODE MFC WINDOWS PROGRAMMING PROGRAMMER STRING CString EXTENSION REGULAR EXPRESSION REGEX REGEXP">
<SCRIPT LANGUAGE="JavaScript">
<!--
var axel = Math.random() + "";
var ord = axel * 1000000000000000000 + "?";
//This part of script alleviates a Netscape document.write bug
<!--
NS4 = document.layers;
if (NS4) {
origWidth = innerWidth;
origHeight = innerHeight;
}
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();
}
if (NS4) onresize = reDo;
//-->
</SCRIPT>
</HEAD>
<body>
<!-- begin logo and top banner ad table -->
<!-- begin lower outer table -->
<TABLE cellpadding="0" cellspacing="0" border="0">
<TR>
<!-- begin content column -->
<TD VALIGN="TOP" >
<!--
<table cellpadding="0" cellspacing="0">
<tr>
-->
<!-- begin main content column -->
<!-- closign of column, row, and table are in subfoot file -->
<CENTER>
<H3>
<FONT COLOR="#AOAO99">Using Regular Expressions for Search/Replace</FONT></H3></CENTER>
<CENTER>
<H3>
<HR></H3></CENTER>
<p>Normally, when you search for a sub-string in a string, the match should be exact. So if we search for a sub-string "abc" then the string being searched should contain these exact letters in the same sequence for a match to be found. We can extend this kind of search to a case insensitive search where the sub-string "abc" will find strings like "Abc", "ABC" etc. That is, the case is ignored but the sequence of the letters should be exactly the same. Sometimes, a case insensitive search is also not enough. For example, if we want to search for numeric digit, then we basically end up searching for each digit independantly. This is where regular expressions come in to our help.
<p>Regular expressions are text patterns that are used for string matching. Regular expressions are strings that contains a mix of plain text and special characters to indicate what kind of matching to do. Here's a very brief turorial on using regular expressions before we move on to the code for handling regular expressions.
<p>Suppose, we are looking for a numeric digit then the regular expression we would search for is "[0-9]". The brackets indicate that the character being compared should match any one of the characters enclosed within the bracket. The dash (-) between 0 and 9 indicates that it is a range from 0 to 9. Therefore, this regular expression will match any character between 0 and 9, that is, any digit. If we want to search for a special character literally we must use a backslash before the special character. For example, the single character regular expression "\*" matches a single asterisk. In the table below the special characters are briefly described.
<p>
<TABLE BORDER CELLSPACING=1 CELLPADDING=7 WIDTH="100%">
<TR><TD WIDTH="7%" VALIGN="TOP" BGCOLOR="#a0a0a0">
<FONT SIZE=2><P>Character</FONT></TD>
<TD WIDTH="93%" VALIGN="TOP" BGCOLOR="#a0a0a0">
<FONT SIZE=2><P>Description</FONT></TD>
</TR>
<TR><TD WIDTH="7%" VALIGN="TOP">
<FONT SIZE=2><P>^</FONT></TD>
<TD WIDTH="93%" VALIGN="TOP">
<FONT SIZE=2><P>Beginning of the string. The expression "^A" will match an 慉
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -