我一直在搜索Stack Overflow,但无法找到正确的代码来纠正,例如。
bibliographystyle{apa}
分为:
\begin{document}
The body of the document goes here...
\newpage
\bibliography{bibliography} % Or whatever you decided to call your .bib file
\usepackage[round, comma, sort&compress ]{natbib}
bibliographystyle{apa}
\end{document}
答案 0 :(得分:2)
例如:
import re
text = 'hello! are you tired? no, not at all!'
punc_filter = re.compile('([.!?]\s*)')
split_with_punctuation = punc_filter.split(text)
final = ''.join([i.capitalize() for i in split_with_punctuation])
print(final)
输出:
>>> Hello! Are you tired? No, not at all!
答案 1 :(得分:2)
您可以尝试这种正则表达式方法:
import re
re.sub("(^|[.?!])\s*([a-zA-Z])", lambda p: p.group(0).upper(), s)
# 'Hello! Are you tired? No, not at all!'
(^|[.?!])
匹配字符串^
或.?!
的开头,后跟可选空格; [a-zA-Z]
在第一个模式后直接匹配字母; 答案 2 :(得分:0)
您可以执行类似
的操作x = "hello! are you tired? no, not at all!"
y = x.split("? ")
z=""
for line in y:
z = "{} {}".format(z,line.capitalize())
print(z)
根据您的需要进行调整。
答案 3 :(得分:0)
capitalize()方法使除第一个字母外的所有字母变小。
更一般的变体是:
def capitalize(text):
punc_filter = re.compile('([.!?;]\s*)')
split_with_punctuation = punc_filter.split(text)
for i,j in enumerate(split_with_punctuation):
if len(j) > 1:
split_with_punctuation[i] = j[0].upper() + j[1:]
text = ''.join(split_with_punctuation)
return text
text = "hello Bob! are you tired? no, not at all!"
capitalize(text)
输出:
'Hello Bob! Are you tired? No, not at all!'