Clojure:我可以使用什么正则表达式来检测多行字符串中一行的最后一个字符?
Clojure: What regular expression can I use to detect the last character of a line in a multi-line string?
我正在尝试匹配 Clojure 中每行(多行文本字符串)末尾的最后一个字符。这是一个示例文本:
"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."
我尝试了 #"\n"
,但只匹配了一个新行。
使用#"\n|$"
; \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....
我正在尝试匹配 Clojure 中每行(多行文本字符串)末尾的最后一个字符。这是一个示例文本:
"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."
我尝试了 #"\n"
,但只匹配了一个新行。
使用#"\n|$"
; \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....