简体   繁体   English

Clojure:我可以用什么正则表达式来检测多行字符串中一行的最后一个字符?

[英]Clojure: What regular expression can I use to detect the last character of a line in a multi-line string?

I am trying to match the last character at the end of each line (multi-line text string) in Clojure. 我想在Clojure中匹配每行末尾的最后一个字符(多行文本字符串)。 Here is a sample text: 这是一个示例文本:

"Possible values:

copy: A copy of the source item is made at the new location.
move: An item is moved to a new location.
link: A link is established to the source at the new location.
none: The item may not be dropped."

I tried #"\\n" but that only matches a new line. 我试过#"\\n"但只匹配一个新行。

Use #"\\n|$" ; 使用#"\\n|$" ; \\n to match all newlines except the last one, and $ to match the last one. \\n匹配除最后一个之外的所有换行符,并且$匹配最后一个换行符。

user=> (print (clojure.string/replace text #"\n|$" "...\n"))
Possible values:...
...
copy: A copy of the source item is made at the new location....
move: An item is moved to a new location....
link: A link is established to the source at the new location....
none: The item may not be dropped....

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

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