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

How to use the m modifier of regular expression

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces the regular expression m modifier how to use, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

Regular expression m modifier:

The m modifier specifies that regular expressions can perform multiline matching.

The m modifier modifies the role of ^ and $in regular expressions so that they represent the beginning and end of a line, respectively.

By default, whether or not a string wraps a line with only one beginning ^ and ending $, if multiple line matching is used, each line has a ^ and ending $.

Grammatical structure:

Constructor mode:

New RegExp ("regexp", "m")

Object direct quantity method:

/ regexp/m

Browsers support:

IE browsers support this metacharacter.

Firefox browser supports this metacharacter.

Google browser supports this metacharacter.

Example code:

Example 1:

Var str= "This is an\ n antzone good"; var reg=/an$/;console.log (str.match (reg))

The above code does not match the string "an". Although there is a line break after "an", it does not use multi-line matching, so it is not the end of the character series.

Example 2:

Var str= "This is an\ n antzone good"; var reg=/an$/m;console.log (str.match (reg))

The above code matches the string "an" because it uses multiple lines of matching.

Example 3:

Var reg = / ^ bBank str var str = 'test\ nbbs';execReg (reg,str)

The match failed because there is no b character at the beginning of the string. But after adding the m modifier:

Example 4:

Var reg = / ^ bBank str var str = 'test\ nbbs';execReg (reg,str)

Match to b, because with the m modifier added, ^ already represents the beginning of the line, and because bbs is at the beginning of the second line of the string, it can be matched successfully.

Thank you for reading this article carefully. I hope the article "how to use the regular expression m modifier" 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