简体   繁体   English

谷歌表格中的正则表达式

[英]Regex in google sheets

I have been trying to extract text with =REGEXREPLACE() in Google Sheets.我一直在尝试在 Google 表格中使用 =REGEXREPLACE() 提取文本。 The aim is to split the string after every third sentence.目的是在每三个句子之后拆分字符串。 I achieved this in regex101 with the following formula: (. ?).我在 regex101 中使用以下公式实现了这一点:(。 ?)。 (. ?). (。 ?)。 (.*?). (.*?)。 and substitution of \\1.并替换 \\1。 \\2. \\2. \\3.\\r\\n\\r\\n. \\3.\\r\\n\\r\\n。

Heres an example of the string I am trying to separate:这是我试图分离的字符串示例:

I am a sentence.我是一个句子。 I am another sentence.我是另一个句子。 Another random sentence to add to the mix.另一个随机句子添加到组合中。 Once again I find myself writing a sentence.我再一次发现自己在写一个句子。 I hope this weekend is sunny in Brisbane.我希望这个周末布里斯班阳光明媚。 The quick brown fox jumps over the lazy dog.敏捷的棕色狐狸跳过了懒狗。 The cat crept into the crypt, crapped and crept out again.猫爬进地窖,拉了几下,又爬了出来。 There are never enough hours in a day.一天的时间永远不够用。 Streaming GeorgeFM from Auckland via the bose soundtouch app is the beez kneez.通过 bose soundtouch 应用程序从奥克兰流式传输 GeorgeFM 是 beez 膝盖。 For good measure, I thought I would write another sentence.为了更好的衡量,我想我会再写一句话。

Using the above I have managed to achieve:使用上述我已经设法实现:

I am a sentence.我是一个句子。 I am another sentence.我是另一个句子。 Another random sentence to add to the mix.另一个随机句子添加到组合中。

Once again I find myself writing a sentence.我再一次发现自己在写一个句子。 I hope this weekend is sunny in Brisbane.我希望这个周末布里斯班阳光明媚。 The quick brown fox jumps over the lazy dog.敏捷的棕色狐狸跳过了懒狗。

The cat crept into the crypt, crapped and crept out again.猫爬进地窖,拉了几下,又爬了出来。 There are never enough hours in a day.一天的时间永远不够用。 Streaming GeorgeFM from Auckland via the bose soundtouch app is the beez kneez.通过 bose soundtouch 应用程序从奥克兰流式传输 GeorgeFM 是 beez 膝盖。

For good measure, I thought I would write another sentence.为了更好的衡量,我想我会再写一句话。

Issues: it does not trim the whitespace at the beginning of sentences and;问题:它不会修剪句子开头的空格; it does not work at all in google sheets!它在谷歌表格中根本不起作用!

Below are the links to Regex101 and Google Sheets.以下是 Regex101 和 Google Sheets 的链接。

Regex101 .正则表达式101

Google Sheets . 谷歌表格

Any ideas?有任何想法吗?

Many thanks.非常感谢。 Ross罗斯

change \\1.\\2.\\3.更改\\1.\\2.\\3. to $1.$2.$3 to get the replace working in google sheets.$1.$2.$3以在 Google 表格中进行替换。

As per this answer , we cannot use regex in the replace string, hence \\r\\n will not work in the replace.根据这个答案,我们不能在替换字符串中使用正则表达式,因此 \\r\\n 在替换中不起作用。

Adding a * (space followed by *) at the beginning of the regex fixes the space issue.在正则表达式的开头添加* (空格后跟 *)可修复空格问题。

Regex: *(.*?)\\. (.*?)\\. (.*?)\\.正则表达式: *(.*?)\\. (.*?)\\. (.*?)\\. *(.*?)\\. (.*?)\\. (.*?)\\.

Demo演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM