Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the application scenarios of regular expressions

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the application scenarios of regular expressions, which can be used for reference. I hope you can learn a lot after reading this article.

What is a regular expression?

Regular expression (Regular Expression) is a concept, a grammatical and syntactic convention. Each of the specific statements (Cellular Java JavaScript) has its own specific implementation of regular expressions, and there will be differences. The 30-minute getting started tutorial on regular expressions deals with. Net (C #) regular expressions.

Regular expression of JavaScript

I am good at JavaScript regular expressions. One of the biggest features of this regular expression is that it does not support zero-width positive review assertions. The reason is simple: js is interpreted and executed. The details will be understood in depth.

Syntax query

A 30-minute introduction to regular expressions

JavaScript RegExp object reference manual

Some of the methods in the JavaScript String object reference manual, such as match,replace,search.

Application scenario

Regular expressions have two major application scenarios 1. Check whether the user's input is legal; 2. Extract the part of the information you want from a pile of information; the biggest difference between the two application scenarios is that the validity of the input is detected for the entire input character, that is, you need to add ^ to match the beginning of the string and $to match the end of the string. Otherwise, it doesn't make much sense, at least I haven't encountered the situation of not adding. The scenario of extracting information generally involves global search g.

A simple example

Just look at the code, how can not master regular expressions, let's practice: open chrome (if you have not installed chrome, then you are not the target reader of this article), of course, the installation of firebug firefox or a higher version of IE also OK, press F12, bring up the developer tool. Switch to the following tab and enter the code

/ Hello World/.test ("Hello World")

OK, the above code uses a regular expression to detect whether a string contains the specific character "Hello World". In JS, the most common is the direct quantity of Regexp, that is, the syntax of regular expressions added to the two slashes / /. In other words, the syntax mentioned in the 30-minute introduction to regular expressions, such as [aeiou],\ (0\ d {2} [) -]?\ d {8}, etc., put in two slashes / / to become a JS regular expression object (/ [aeiou] /, /\ (? 0\ d {2} [) -]?\ d {8} /) has the methods mentioned in the JavaScript RegExp object reference manual. It can also be applied to some of the methods in the JavaScript String object reference manual before it can be applied to actual programming, as shown in the Hello World sample code above. Finally, according to my own experience, I have to do a practice on my own, such as

1. Extract the body part of this article, or extract the text from all the hyperlinks

two。 Design a form to verify the user's input. For specific verification, you can refer to common regular expressions.

Thank you for reading this article carefully. I hope the article "what are the application scenarios of regular expressions" shared by the editor will be helpful to everyone? at the same time, I also hope that you will support 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report