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 matching rules for regular expressions?

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

Share

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

In this issue, the editor will bring you what are the matching rules of regular expressions. The article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.

On the\ matching rules of regular expression raw

This is an example I got in my study. The match in the first expression is none. So I was thinking, why it doesn't match, assuming\ t is escaped as a\ t, then it should also match to\ tsanle, not none.

In order to verify this problem, I did the following experiments:

So why is there such a result? in a regular expression, the string you need to find is escaped twice, first the incoming string is converted at the first level, for example:\ t->\ t. Then pass it to the re parser for the second layer transformation,\ t-- > tab key. The string that needs to match\\ t-> the two backslashes will become a backslash (because the previous\ will escape the latter\, so the two will become one). And then it becomes\ t, and then it becomes a direct tab, and they match.

When raw appears, it is as follows:

What can match becomes unmatched. Why, because the first-level transformation that would have taken place after using raw no longer exists, go directly to the re parser for the second-level transformation:

For example:\\ tsanle-- > becomes\ tsanle after only one conversion. However, the string that needs to be matched is still converted before. With only one tab, they will not be able to match.

That's what I understand. If you have any doubts, you can ask questions in private. This is what I understand as regular rules.

These are the matching rules of regular expressions shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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