SQL表名清理的正则表达式 [英] Regex for SQL Table Name Cleanup
本文介绍了SQL表名清理的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要针对用户输入的sting运行检查,这将成为SQL Server数据库上动态创建的表的名称。我只是想确保我正确使用此正则表达式并且不会遗漏任何内容。我是否用这个表达式覆盖了标识符格式规则的所有基础?
I need to run a check against a user inputted sting that will become the name of a dynamically created table on a SQL Server database. I just wanted to make sure that I was getting this Regex correct and not missing anything. Am I covering all the bases for the identifier format rules with this expression?
System.Text.RegularExpressions.Regex.Replace(tableName, @"[^\w\.@$#]", "");
这是我第一次使用正则表达式并且想要格外小心。
It's the first time I've used a regular expression and wanted to be extra careful.
推荐答案
#], );
这是我第一次使用正则表达式并希望格外小心。
It's the first time I've used a regular expression and wanted to be extra careful.
在那里你会找到SQL Server字符串标识符的规则:
数据库标识符 [ ^ ](参见'Rul本页中常规标识符的es。)
[更正]我没有正确读取代码。显然你试图替换所有不是单词,点,@,#或
There you will find the rules for SQL Server string identifiers:
Database Identifiers[^] (see 'Rules for Regular Identifiers' in this page).
[Correction] I did not read the code correctly. Apparently you are trying to replace all characters that are not a word, a point, a @, # or
的字符。
我不认为某个点可以是标识符的一部分。
.
I don't think a point can be part of an identifier.
这篇关于SQL表名清理的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文