您好我想创建一个正则表达式来查找在它们之间有大写单词的单词。谁能告诉我如何找到它?
例如:I went to a school forEducation and then didn't study.
我想要像forEducation
这样的词。我想我们使用[a-z][A-Z]
来查找所有字母但却找不到它。我正在考虑合并上述两个选项,但那么如何检查大写字母?此外,我不想选择任何在开头有大写字母的单词,因为它们是有效的。
原因:这是因为从在线网站抓取文字并且没有正确的格式。我把这些单词作为文本,并想要替换它们。
答案 0 :(得分:1)
[a-zA-Z][a-z]*[A-Z][a-zA-Z]*
以任何字母开头,后跟0或更多小写字母,后跟大写字母,后跟0或更多字母(大写或不大写)
答案 1 :(得分:1)
如果我猜对了,你想要拆分camelCased的单词,对吧?
然后使用
ResultString = Regex.Replace(SubjectString,
"(?<=\p{Ll}) # Assert that the previous character is a lowercase letter" & chr(10) & _
"(?=\p{Lu}) # Assert that the next character is an uppercase letter",
" ", RegexOptions.IgnorePatternWhitespace)
此更改
I went to a school forEducation and then didn't study.
到
I went to a school for Education and then didn't study.