【发布时间】:2014-07-17 18:53:32
【问题描述】:
我想在整行上查找上面有空行但在下一行有文本的字符串。然后我希望找到的字符串是大写的。我永远不会提前知道这些名字。 (我在Google Apps Script 中这样做)。
示例文本:
susan jones
Good morning, children. How are you today?
Susan jones is a 1st grade school teacher. bob smith is a plumber.
bob smith
Hello, Susan. You are nice.
我想把所有说话人的名字都大写。所以文本将如下所示:
SUSAN JONES
Good morning, children. How are you today?
Susan jones is a 1st grade school teacher. Bob smith is a plumber.
BOB SMITH
Hello, Susan. You are nice.
【问题讨论】:
-
^(\w+ \w+)\s*$仅查找 name 和 surname ,因此将其替换为大写,\U\1。通过发现这一点,我们假设用户的文本不仅仅是两个单词 -
谢谢!实际上,名字可以出现在任何变体中:Susan、Susan Jones、Doctor Susan Jones、Doctor Susan Jones Sr. 等。我尝试过:
^((\w+ \w+)|(\w+)|(\w+ \w+ \w+)|(\w+ \w+ \w+ \w+))\s*$一直有效,直到它碰到一个结尾有句点的字符串。
标签: javascript regex google-apps-script