zoukankan      html  css  js  c++  java
  • VS.Net 正则表达式.

    VS.Net2010 里的 正则表达式是用 {} 来捕获分组. 用 \1 \2 来获取分组内容的.

    Vs2012+的版本,使用 $1 $2 获取分组内容

    如:在SQL SERVER 执行 drop table 时,可能有外键引用阻止。可以建立如下存储过程:

    alter proc DropTable (@tab nvarchar(250) )
    as begin
    
        declare @str nvarchar(max) ;
        set @str = N'' ;
        
    
        select @str = @str + N'ALTER TABLE [' + object_name( parent_object_id)  + '] DROP CONSTRAINT [' +  name + '];'
        from sys.foreign_keys 
        where   referenced_object_id  = object_id( @tab)
    
        exec sp_executesql @str ;
    
        if exists (select 1
                    from  sysobjects
                    where  id = object_id('ResKey')
                    and   type = 'U')
        begin
            set @str = N'Drop table ' + @tab ;
            exec sp_executesql  @str ;
        end
    
    end;

    典型应用:

    1. 把 : drop table A    替换为: exec DropTable 'A'

    使用正则 搜索: drop table:b*{.*}

    替换为: DropTable '\1'

    2. 把  PK="ID" 去除。

    搜索: PKs="[^\"]*"  替换为 空

    3. 搜索类似于  $("#任何字符",  即以 #选择器的文本。 像: $("#row1",jt)  

    \$\("\#[^"]+\"\,

    4.  把 属性定义的属性名提取出来。

    public string IID { get; set; }    

    public string Memo { get; set; }

    =》

    "IID","Memo"

    用如下正则:

    public:b*:i:b*{[a-z|A-Z]*}:b*\{:b*get;:b*set;:b*\}      替换为 "\1",

    以上使用的是 VS2010

    VS2012的例子:

    5.参数重排: 把第一个参数和第二个参数置换。

     jv\.confirm\([^\S\r\n]*([^,]*)[^\S\r\n]*\,[^\S\r\n]*([^,]*)[^\S\r\n]*\,

    替换为: jv.confirm($2,$1,

    6. <input /> 改为 <button>

    (\<input)(.*? )value="(.*?)"(.*?)\/>

    =>

    <button$2$4>$3</button>

    alarm   作者:NewSea     出处:http://newsea.cnblogs.com/    QQ,MSN:iamnewsea@hotmail.com

      如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。
  • 相关阅读:
    递归和分类问题之间的区别
    基于TF-IDF的推荐
    mnist
    服饰分类的神经网络模型
    基于内容的推荐
    深度学习-术语
    FiBiNET-学习
    30,新起点,再出发。
    md5加盐加密
    批处理for命令中的/r和/d参数
  • 原文地址:https://www.cnblogs.com/newsea/p/1876953.html
Copyright © 2011-2022 走看看