Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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
Oracle regexp_replace-为单独的句子添加空格_Regex_Oracle_Oracle12c - Fatal编程技术网

Oracle regexp_replace-为单独的句子添加空格

Oracle regexp_replace-为单独的句子添加空格,regex,oracle,oracle12c,Regex,Oracle,Oracle12c,我在甲骨文公司工作,修复一些文本。问题是,我的数据中的句子有一些单词,其中句子之间没有空格分隔。例如: 没有空格的句子。句子之间 带问号的句子?第二句 我已经在regex101中测试了以下replace语句,它似乎在那里工作,但我无法确定它在Oracle中不工作的原因: regexp_replace(review_text, '([^\s\.])([\.!\?]+)([^\s\.\d])', '\1\2 \3') 这将允许我查找分隔句点/感叹号/问号(单个或成组)的句子,并在句子之间添加必要的

我在甲骨文公司工作,修复一些文本。问题是,我的数据中的句子有一些单词,其中句子之间没有空格分隔。例如:

  • 没有空格的句子。句子之间

  • 带问号的句子?第二句

  • 我已经在regex101中测试了以下replace语句,它似乎在那里工作,但我无法确定它在Oracle中不工作的原因:

    regexp_replace(review_text, '([^\s\.])([\.!\?]+)([^\s\.\d])', '\1\2 \3')
    
    这将允许我查找分隔句点/感叹号/问号(单个或成组)的句子,并在句子之间添加必要的空格。我意识到还有其他的方法可以把句子分开,但我上面的内容应该涵盖绝大多数用例。第三个捕获组中的\d是为了确保我没有意外地将“4.5”之类的数值更改为“4.5”

    试验组前:

    Sentence without space.Between sentences
    Sentence with space. Between sentences
    Sentence with multiple periods...Between sentences
    False positive sentence with 4.5 Liters
    Sentence with!Exclamation point
    Sentence with!Question mark
    
    更改后应如下所示:

    Sentence without space. Between sentences
    Sentence with space. Between sentences
    Sentence with multiple periods... Between sentences
    False positive sentence with 4.5 Liters
    Sentence with! Exclamation point
    Sentence with! Question mark
    
    Regex101链接:

    虽然所有的更改都按照regex101的预期工作,但我的问题是,我进入Oracle的原因是我的第三个和第四个测试用例没有按预期工作。Oracle没有在多句点(省略号)组后添加空格,而regexp_replace正在为“4.5”添加空格。我不确定为什么会出现这种情况,但也许Oracle regexp_replace有一些我没有注意到的特性


    任何和所有的洞察力都是值得赞赏的。谢谢

    这可能会让你开始。这将检查是否存在错误。?!在任何组合中,后跟零个或多个空格和一个大写字母,它将用正好一个空格替换“零个或多个空格”。这不会分隔十进制数;但它会漏掉以大写字母以外的任何字母开头的句子。您可以开始添加条件-如果遇到困难,请回信,我们将尽力提供帮助。参考其他regex方言可能会有所帮助,但这可能不是获得答案的最快方法

    with
         inputs ( str ) as (
           select 'Sentence without space.Between sentences'           from dual union all
           select 'Sentence with space. Between sentences'             from dual union all
           select 'Sentence with multiple periods...Between sentences' from dual union all
           select 'False positive sentence with 4.5 Liters'            from dual union all
           select 'Sentence with!Exclamation point'                    from dual union all
           select 'Sentence with!Question mark'                        from dual
         )
    select regexp_replace(str, '([.!?]+)\s*([A-Z])', '\1 \2') as new_str
    from   inputs;
    
    NEW_STR
    -------------------------------------------------------
    Sentence without space. Between sentences
    Sentence with space. Between sentences
    Sentence with multiple periods... Between sentences
    False positive sentence with 4.5 Liters
    Sentence with! Exclamation point
    Sentence with! Question mark
    
    6 rows selected.
    

    这可能会让你开始。这将检查是否存在错误。?!在任何组合中,后跟零个或多个空格和一个大写字母,它将用正好一个空格替换“零个或多个空格”。这不会分隔十进制数;但它会漏掉以大写字母以外的任何字母开头的句子。您可以开始添加条件-如果遇到困难,请回信,我们将尽力提供帮助。参考其他regex方言可能会有所帮助,但这可能不是获得答案的最快方法

    with
         inputs ( str ) as (
           select 'Sentence without space.Between sentences'           from dual union all
           select 'Sentence with space. Between sentences'             from dual union all
           select 'Sentence with multiple periods...Between sentences' from dual union all
           select 'False positive sentence with 4.5 Liters'            from dual union all
           select 'Sentence with!Exclamation point'                    from dual union all
           select 'Sentence with!Question mark'                        from dual
         )
    select regexp_replace(str, '([.!?]+)\s*([A-Z])', '\1 \2') as new_str
    from   inputs;
    
    NEW_STR
    -------------------------------------------------------
    Sentence without space. Between sentences
    Sentence with space. Between sentences
    Sentence with multiple periods... Between sentences
    False positive sentence with 4.5 Liters
    Sentence with! Exclamation point
    Sentence with! Question mark
    
    6 rows selected.
    

    我的猜测是,在regex101中启用的是全局匹配(g标志),而在Oracle中没有启用。全局匹配是我没有想到的,但即使在Oracle中使用设置“发生率=0”,我仍然会遇到同样的问题。我的猜测是,这是全局匹配(g标志)这是在regex101中启用的,而不是在Oracle中启用的。全局发生率是我没有想到的,但即使在Oracle中使用设置“发生率=0”,我仍然会遇到相同的问题。谢谢mathguy-您编写的内容在逻辑上是合理的。我将应用你所给出的(尽管我也将使用小写的a-z),并检查是否有遗漏。谢谢mathguy-你所写的合乎逻辑。我将应用您提供的内容(尽管我也将使用小写的a-z),并检查是否缺少任何内容。