Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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
Php 正则表达式并没有拆分这句话_Php_Regex - Fatal编程技术网

Php 正则表达式并没有拆分这句话

Php 正则表达式并没有拆分这句话,php,regex,Php,Regex,我使用下面的代码来分割句子,它工作得很好,但是在下面的例子中,它只是抛出了一个错误。知道为什么它不能得到这个句子吗 $re = '/# Split sentences on whitespace between them. (?<= # Begin positive lookbehind. [.!?:] # Either an end of sentence punct, | [.!?:][\'"]

我使用下面的代码来分割句子,它工作得很好,但是在下面的例子中,它只是抛出了一个错误。知道为什么它不能得到这个句子吗

 $re = '/# Split sentences on whitespace between them.
     (?<=                # Begin positive lookbehind.
       [.!?:]            # Either an end of sentence punct,
     | [.!?:][\'"]
     | [\r\t\n]         # or end of sentence punct and quote.
     )                   # End positive lookbehind.
     (?<!                # Begin negative lookbehind.
       Mr\.              # Skip either "Mr."
     | Mrs\.             # or "Mrs.",   
     | Ms\.              # or "Ms.",
     | Jr\.              # or "Jr.",
     | Dr\.              # or "Dr.",
     | Prof\.            # or "Prof.",
     | U\.S\.A\.
     | Sr\.              # or "Sr.",
     | T\.V\.A\.         # or "T.V.A.",
     | a\.m\.            # or "a.m.",
     | p\.m\.            # or "p.m.",
     | a€¢\.
     | :\.
     | ?\.

                         # or... (you get the idea).
     )                   # End negative lookbehind.
     \s+                 # Split on whitespace between sentences.

     /ix';

 $english = "Support services, such as help with transportation or clothing, may also be available. How do I receive these services?";

 $english = preg_split($re, $row['english'], -1, PREG_SPLIT_NO_EMPTY);

 print_r($english);

??是一个特殊角色,您需要对其进行转义:

$re = '/# Split sentences on whitespace between them.
 (?<=                # Begin positive lookbehind.
   [.!?:]            # Either an end of sentence punct,
 | [.!?:][\'"]
 | [\r\t\n]         # or end of sentence punct and quote.
 )                   # End positive lookbehind.
 (?<!                # Begin negative lookbehind.
   Mr\.              # Skip either "Mr."
 | Mrs\.             # or "Mrs.",   
 | Ms\.              # or "Ms.",
 | Jr\.              # or "Jr.",
 | Dr\.              # or "Dr.",
 | Prof\.            # or "Prof.",
 | U\.S\.A\.
 | Sr\.              # or "Sr.",
 | T\.V\.A\.         # or "T.V.A.",
 | a\.m\.            # or "a.m.",
 | p\.m\.            # or "p.m.",
 | a€¢\.
 | :\.
 | \?\.              # <=== over here.

                     # or... (you get the idea).
 )                   # End negative lookbehind.
 \s+                 # Split on whitespace between sentences.

 /ix';
$re='/#用空格分隔句子。
(?丹尼尔抓得好。
说有一个量词,但没有量词。
既然你已经把它扩展了,就没有什么可以量化的了。如果是文字,就应该转义

     # Split sentences on whitespace between them.
     (?<=                          # Begin positive lookbehind.
          [.!?:]                        # Either an end of sentence punct,
       |  [.!?:] ['"] 
       |  [\r\t\n]                      # or end of sentence punct and quote.
     )                             # End positive lookbehind.
     (?<!                          # Begin negative lookbehind.
          Mr\.                          # Skip either "Mr."
       |  Mrs\.                         # or "Mrs.",   
       |  Ms\.                          # or "Ms.",
       |  Jr\.                          # or "Jr.",
       |  Dr\.                          # or "Dr.",
       |  Prof\.                        # or "Prof.",
       |  U\.S\.A\.
       |  Sr\.                          # or "Sr.",
       |  T\.V\.A\.                     # or "T.V.A.",
       |  a\.m\.                        # or "a.m.",
       |  p\.m\.                        # or "p.m.",
       |  a€¢\.
       |  :\.
       |  
=         ?  <-- Quantifies nothing
          \.

                                        # or... (you get the idea).
     )                             # End negative lookbehind.
     \s+                           # Split on whitespace between sentences.
#用空格分隔句子。

(?谢谢!在我使用的原始代码中,这不是一个。当我将它移动到一个新脚本时,它不知怎么地发生了变化。非常感谢,我在这个脚本上掉了很多头发。
     # Split sentences on whitespace between them.
     (?<=                          # Begin positive lookbehind.
          [.!?:]                        # Either an end of sentence punct,
       |  [.!?:] ['"] 
       |  [\r\t\n]                      # or end of sentence punct and quote.
     )                             # End positive lookbehind.
     (?<!                          # Begin negative lookbehind.
          Mr\.                          # Skip either "Mr."
       |  Mrs\.                         # or "Mrs.",   
       |  Ms\.                          # or "Ms.",
       |  Jr\.                          # or "Jr.",
       |  Dr\.                          # or "Dr.",
       |  Prof\.                        # or "Prof.",
       |  U\.S\.A\.
       |  Sr\.                          # or "Sr.",
       |  T\.V\.A\.                     # or "T.V.A.",
       |  a\.m\.                        # or "a.m.",
       |  p\.m\.                        # or "p.m.",
       |  a€¢\.
       |  :\.
       |  
=         ?  <-- Quantifies nothing
          \.

                                        # or... (you get the idea).
     )                             # End negative lookbehind.
     \s+                           # Split on whitespace between sentences.