Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.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/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.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
通过识别句点、空格,然后是下一个句子的大写字母来获取MySQL字符串中的第一个句子_Mysql_Regex_Substring - Fatal编程技术网

通过识别句点、空格,然后是下一个句子的大写字母来获取MySQL字符串中的第一个句子

通过识别句点、空格,然后是下一个句子的大写字母来获取MySQL字符串中的第一个句子,mysql,regex,substring,Mysql,Regex,Substring,String1=“Widgets Inc.是世界上最大的Widgets生产商。比McWidgets Inc.大得多。” String2=“Fidgets Inc.是第二大Fidgets生产商。紧随McFidgets Inc.之后。该公司的首席执行官热爱synergy。” String3=“光荣的Gagets公司被认为是胡说八道的jdfglmdslgmldfg。” 对于上述所有场景,我只想可靠地选择第一句话。我将使用: [编辑]:注意句子中没有真正的句型 SUBSTRING\u索引(字符串,'.'

String1=“Widgets Inc.是世界上最大的Widgets生产商。比McWidgets Inc.大得多。”

String2=“Fidgets Inc.是第二大Fidgets生产商。紧随McFidgets Inc.之后。该公司的首席执行官热爱synergy。”

String3=“光荣的Gagets公司被认为是胡说八道的jdfglmdslgmldfg。

对于上述所有场景,我只想可靠地选择第一句话。我将使用:

[编辑]:注意句子中没有真正的句型

SUBSTRING\u索引(字符串,'.',1)

但是,这会导致第一个和第三个字符串出现问题,因为它们有时在名称后面有“.”,有时没有

我的想法是使用类似于子字符串的索引(字符串,“[A-Z]”,1),本质上告诉它查找第一个“.”,后面跟着一个空格,然后是任何大写字母(即下一个句子的开头),但我的SQL fu还不够强大,无法弄清楚如何做到这一点


任何帮助都将不胜感激

当有固定模式时,可以使用LOCATE查找索引,然后使用SUBSTRING将其删除。对于startung点,如果不想使用函数或存储过程,则需要正则表达式,而对于更复杂的模式,也需要正则表达式

|子字符串(tex,REGEXP_INSTR(tex,[A-Z]”),定位(“世界上的生产商”,tex)+21)| | :--------------------------------------------------------------------------------- | |Widgets Inc.是世界上最大的Widgets生产商| |Fidgets Inc是世界上最大的Fidgets生产商|
dbfiddle

K看起来我有一个解决办法,就是在没有按照请求的方式实际识别句子的情况下,即通过在substring参数中包含大写字母检查


找到包含句号的缩写列表(如Co.,Inc.,Ltd.,等),并硬编码以替换不带句号的缩写-Co,Ltd.,Inc.,等。。。然后按正常方式执行子字符串。虽然不理想,但效果很好。

谢谢您的回答!我想我应该更详细一点。不幸的是,这些句子不一定遵循这样的模式。我已经编辑了这个问题,然后在世界上重现它。只要你有一个图案就行了。Yoi还可以识别出。在模式的末尾,对概念进行了全面的描述,您现在必须对其进行调整。对于更复杂的事情,您必须对其进行tpo编程—所有无法通过egex或instr识别或定位的事情,您必须自己编写一个字处理器。
CREATE TABLE table1 (tex varchar(200))
INSERT INTO table1 VALUES ("Widgets Inc. is the largest widgets producer in the world. It's much bigger than McWidgets Inc.")
,("Fidgets Inc is the largest fidgets producer in the world. It's much bigger than McFidgets Inc.")
SELECT SUBSTRING(tex,REGEXP_INSTR(tex, '[A-Z]'),LOCATE('producer in the world.',tex)+ 21) FROM table1
| SUBSTRING(tex,REGEXP_INSTR(tex, '[A-Z]'),LOCATE('producer in the world.',tex)+ 21) | | :--------------------------------------------------------------------------------- | | Widgets Inc. is the largest widgets producer in the world. | | Fidgets Inc is the largest fidgets producer in the world. |