Unless you have used regular expressions before, you may not be familiar with some terms. However, there is no doubt that you have used some concepts of regular expressions that do not involve scripts.
例如,您很可能使用 ? 和 * 通配符来查找硬盘上的文件。? 通配符匹配文件名中的 0 个或 1 个字符,而 * 通配符匹配零个或多个字符。像 data(w)?.dat 这样的模式将查找下列文件:
data.dat
data1.dat
data2.dat
datax.dat
dataN.dat
Use* 字符代替 ? 字符扩大了找到的文件的数量。data.* . Dat matches all the following files:
data.dat
data1.dat
data2.dat
data12.dat
datax.dat
dataXYZ.dat
Although this search method is useful, it is limited. By understanding how wildcards work, the concepts that regular expressions depend on are introduced, but regular expressions are more powerful and more flexible.
The use of regular expressions can achieve powerful functions in a simple way. Here’s a simple example:

The starting position of the input string for the match.
[0-9] + match multiple digits [0-9] Match a single number, + match one or more.
Abc$ matches the letter abc and ends with abc, with $as the end of the matching input string.
When we write the user registration form, only allow the user name to contain characters, numbers, underscores and connection characters-and set the length of the user name, we can use the following regular expression to set it.

The above regular expressions can match runoob、runoob1、run-oob、run_oob But it doesn’t match. ru Because it contains letters that are too short to match with less than three It doesn’t match. runoob$ Because it contains special characters Matches a string that begins with a number and ends with abc. : The text of the following tag is the obtained matching expression: Continuing to read this tutorial will give you the freedom to apply such code. A typical search and replace operation requires you to provide exact text that matches the expected search results. While this technique may be sufficient for performing simple search and replacement tasks on static text, it lacks flexibility, and it can at least become difficult, if not impossible, to search for dynamic text in this way. By using regular expressions, you can: Test the pattern within the string. For example, you can test the input string to see if a phone number pattern or a credit card number pattern appears within the string. This is called data validation. Replace the text. You can use regular expressions to identify specific text in a document, delete the text completely, or replace it with other text. Extract a substring from a string based on pattern matching. You can find specific text within the document or in the input field. For example, you may need to search the entire site, remove obsolete materials, and replace some HTML format tags. In this case, you can use regular expressions to determine whether the material or the HTML format tag appears in each file. This procedure narrows the list of affected files to those that contain materials that need to be deleted or changed. You can then use regular expressions to remove obsolete materials. Finally, you can use regular expressions to search for and replace tags. The “ancestor” of canonical expressions can be traced back to early studies of how the human nervous system works. Two neurophysiologists Warren McCulloch and Walter Pitts have developed a mathematical way to describe these neural networks. In 1956, a mathematician named Stephen Kleene, based on the early work of McCulloch and Pitts, published a paper entitled “representation of neural network events”, which introduced the concept of regular expressions. Regular expressions are used to describe what he calls “algebra of regular sets”, so the term “regular expressions” is adopted. Subsequently, it was found that this work could be applied to some early research on computational search algorithms using Ken Thompson, the main inventor of Unix. The first utility for regular expressions is the qed editor in Unix. As they say, the rest is well-known history. Regular expressions have been an important part of text-based editors and search tools since then. At present, regular expressions have been widely used in many software, including nix (Linux, Unix, etc.), HP and other operating systems, PHP, C#, Java and other development environments, as well as many application software, we can see the shadow of regular expressions. In our C# tutorial C# 正则表达式 This chapter is devoted to the knowledge of C # regular expressions. In our Java tutorial Java 正则表达式 This chapter is devoted to the knowledge of Java regular expressions. In our JavaScript tutorial JavaScript RegExp 对象 This chapter is devoted to the knowledge of JavaScript regular expressions, and we also provide a complete JavaScript RegExp 对象参考手册 . In our basic Python tutorial Python 正则表达式 This chapter is devoted to the knowledge of Python regular expressions. In our Ruby tutorial Ruby 正则表达式 This chapter is devoted to the knowledge of Ruby regular expressions. Command or environment . [ ] ^ $ () \} ? (.) Vi √ √ √ √ √ Visual C++ √ √ √ √ √ Awk √ √ √ √ Awk supports this syntax by adding the parameter– posix or– re-interval on the command line. You can see the interval expression in man awk. √ √ √ √ Sed √ √ √ √ √ √ Delphi √ √ √ √ √ √ √ √ √ Python √ √ √ √ √ √ √ √ √ √ Java √ √ √ √ √ √ √ √ √ √ Javascript √ √ √ √ √ √ √ √ √ Php √ √ √ √ √ Perl √ √ √ √ √ √ √ √ √ C# √ √ √ √ √ √ √ √ 14.2.1. Example ¶
varstr="123abc";varpatt1=
/^[0-9]+abc$/;document.write(str.match(patt1));
123abc
14.2.2. Why use regular expressions? ¶
14.2.3. History of development ¶
14.2.4. Application field ¶
14.2.5. C # regular expression ¶
14.2.6. Java regular expression ¶
14.2.7. JavaScript regular expression ¶
14.2.8. Python regular expression ¶
14.2.9. Ruby regular expression ¶