多个不同单词的正则表达式,在空格之间

Regex for multiple different words, between white spaces

我对正则表达式完全陌生。 我只是想知道这是否可能。(如果解释令人困惑或太复杂,我很抱歉) 比如说,我只想查找并替换这个特定的粗体标题:

"As discussed in chapter 1, the users of financial statements can be categorised as resource provider. (space)(space)Users and decision making(space)(space) An example for this. (space)(space)Nature and purpose of financial analysis(space)(space) We have identi fied that financial analysis mvolves expressing reported numbers in financial statements in relative terms. "

对此:

"As discussed in chapter 1, the users of financial statements can be categorised as resource provider.
(new line) Users and decision making (tab space) An example for this.
(new line) Nature and purpose of financial analysis (tab space) We have identi fied that financial analysis mvolves expressing reported numbers in financial statements in relative terms. "

由于我目前对正则表达式的了解有限,我尝试将其分为两部分:


1. to find ". (space)(space)Nature" :
[(.)]\s\s[(A-Z)]\w+
to \n$&


2. to find "analysis(space)(space) We" :
[(a-z)]\w+\s\s[(A-Z)]
to ??

所以,我的问题是是否可以只定义 1 个正则表达式
(space)(space)用户和决策制定(space)(space)
(space)(space)财务分析的性质和目的(space)(space) 我们

并替换为上面的示例?

谢谢!

PS. The reason behind this weird editing is to upload this to anki flashcard software as txt without further editing.
My current method can be quite taxing if I were to edit the whole text from a thick textbooks (which can contain more than 1000 editing per chapter x20 or so chapters x5 textbooks and more).
fyi, in anki and several other flashcard softwares, tab is the field separator between the front/question and the back/answer.
The double space[ ][ ] is used to separate specific heading from the single space when using find and replace; which has been pre-set by myself beforehand.
The new line (\n) is for adding new separate flashcards.
Anki (and several other flashcard softwares) supports html so I usually added multiple cards by copying the text from pdf using notepad++ and regex find and replace several heading or first word of a sentence to suit with the question/front part of anki flashcard while the rest becomes the answer part; and then import it to anki. If it is possible to automate all the finding part, I can save a helluva lot of time!

经过一段时间的谷歌搜索和修改,我想我终于找到了答案! :D
[ ]{2,}([A-Z])[\w]{1,}[ ]{2,}
替换为
\n$&\t\t

http://regexr.com/3db4o

灵感来自:
Regex for multiple words split by spaces
Python regex: Including whitespace inside character range
http://www.rexegg.com/regex-quickstart.html 和@Jan 的回答

我看到您正在尝试匹配带有大写字母的单词组合,在单词之间有一个 space,并用两个 space 块括起来。

这是满足这些条件的正则表达式:

/[^\S\r\n]{2,}[A-Z]\w*(?:[^\S\r\n]\w+)*[^\S\r\n]{2,}/g

查看 regex demo(替换为 \n$&\t\t

请注意,[\w ]{1,} 将匹配单词字符或 space 1+ 次,并且单词之间可以允许超过 1 个 space。但是,如果您需要在一行上匹配 last 2-space 块可能会更好。请注意,您需要在上面的模式中的第二个 [^\S\r\n] 之后添加一个 +