Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 正则表达式:查找一个模式后跟另一个有间隙的模式_Regex - Fatal编程技术网

Regex 正则表达式:查找一个模式后跟另一个有间隙的模式

Regex 正则表达式:查找一个模式后跟另一个有间隙的模式,regex,Regex,我有一个包含数百条SQL Insert语句的文件。我只想识别那些以HTML段落标记开头的语句,但是没有结尾的段落标记 我在试这些线路 <p>[^\n]*(?!</p>) <-- a <p> followed by any number of characters until \n and then </p> [^\n]*(?!)如果您使用此选项: (\(\d+,\d+,'*?)()('\),) 您将返回对以下部分的引用: (1,1,“放射治

我有一个包含数百条SQL Insert语句的文件。我只想识别那些以HTML段落标记开头的语句,但是没有结尾的段落标记

我在试这些线路

<p>[^\n]*(?!</p>) <-- a <p> followed by any number of characters until \n and then </p>
[^\n]*(?!

)如果您使用此选项:

(\(\d+,\d+,'*?)(

)('\),)

您将返回对以下部分的引用:


  • (1,1,“放射治疗使用一束高能射线(或粒子)淋巴结。
    如果您可以确定

    后面总是有一个引号
    以下在Perl中工作(没有记事本++)

    /[^\n]*(?)(?=')/gx
    

    (为了清晰起见,/x允许空格)。这是一个消极的后向查找,定位在报价的前向上。

    结束

    总是在
    之前)
    ?您使用的是什么语言或工具用有效的解决方案更新了我的答案。@Sepster否。它可能在语句之间。@justintime Java和Javascript非常感谢。我知道这是怎么回事。我正在使用regexbuddy和其他工具,比如Notepad++,我不想特别编写代码来实现这一点。这是一次性的事情,我只是想找到一种识别和替换模式的方法。我不确定在RegEx Buddy或Notepad++中替换.Net样式是否有效。你有什么想法吗?@Ali看起来记事本++没有执行可选的

    )?
    捕获。替换字符串可能是eg
    \1

    \3
    (即反斜杠,而不是美元符号)。应该说你一开始就在使用这些工具!;-)给我发送SQL文件,我会修复它,如果你愿意的话?sepster在internode.on.netNo后面不总是有报价,但你的解决方案给了我更多的想法。谢谢
    INSERT INTO `help` VALUES 
    (1,1,'<p>Radiotherapy uses a beam of high&#45;energy rays (or particles) lymph nodes.</p>'),
    (2,1,'<p>EBRT delivers radiation from a machine outside the body. '),
    (3,1,'<p>Following lumpectomy radiotherapy <ul><li>Heading</li></ul></p>'),
    
    string input = @"INSERT INTO `help` VALUES 
    (1,1,'<p>Radiotherapy uses a beam of high&#45;energy rays (or particles) lymph nodes.</p>'),
    (2,1,'<p>EBRT delivers radiation from a machine outside the body. '),
    (3,1,'<p>Following lumpectomy radiotherapy <ul><li>Heading</li></ul></p>'),";
    
    Regex r = new Regex(@"(\(\d+,\d+,'<p>.*?)(</p>)?('\),)");
    string output = r.Replace(input, "$1</p>$3");
    
    Console.Write(output);
    
    INSERT INTO `help` VALUES
    (1,1,'<p>Radiotherapy uses a beam of high&#45;energy rays (or particles) lymph nodes.</p>'),
    (2,1,'<p>EBRT delivers radiation from a machine outside the body. </p>'),
    (3,1,'<p>Following lumpectomy radiotherapy <ul><li>Heading</li></ul></p>'),
    
    /<p> [^\n]* (?<! <\/p> )  (?=') /gx