In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
How to use regular expression matching comment tsql statements, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Let's look at some examples:
The code is as follows:
-- get the count information of the table select count (*) from T with (nolock)
-- get the count information of a specific value select count (*) from T with (nolock) where v ='--value'
-- get the count information of table'T' select count (*) from T with (nolock)
SELECT * from T-- get table TWhere P
Let's first try to give a simple match:
The code is as follows:\-[^\ r\ n] * $
You will find that it even matches the SQL of the second item, which is wrong. It seems that we should rule out the "'" inside, and then we will change it:
The code is as follows:\-[^\'\ r\ n] {0,} $
Still not right, although the second SQL does not match, but even the third does not match, it still looks wrong.
So how on earth can we really match all the SQL comments?
First, let's summarize some of the features of SQL comments:
1. Start with--
two。 The contents of the comments should not be included in a pair of''.
3. Comments should only appear at the end, before which some statements can optionally appear
Well, after collecting these, the syntax of our final SQL comment also comes out: the copy code is as follows:\ -\-([^\'\ r\ n] {0,} (\'[^\'\ r\ n] {0,}\') {0,} $
All four SQL comments match. Regular expressions are too powerful.
A small problem with this SQL statement is that there cannot be a single single quotation mark after it, otherwise there will be a matching problem. (because it is customary for such delimiters to appear in pairs by default, this small problem can actually be ignored.)
After reading the above, have you learned how to use regular expressions to match annotated tsql statements? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.