英文:
Regular Expression to insert a dash before the final character?
问题
Jan104ac-a
英文:
Totally new at this and no search has been able to help me.
Trying to turn:
Jan104aca
Into:
Jan104ac-a
/(?<=.)(?!$)
Gets me to every space, just not sure how to isolate the final space
Thanks!
答案1
得分: 2
你可以尝试:
(.*)(.)
并将其替换为:
-
<details>
<summary>英文:</summary>
You can try:
```none
(.*)(.)
and substitute it for:
-
答案2
得分: 1
Find: (.)$
Replace: -$1
演示
英文:
You may try the following find and replace, in regex mode:
Find: (.)$
Replace: -$1
答案3
得分: 1
以下是要翻译的内容:
Search for:
(?=.$)
Replace with:
-
Demo: https://regex101.com/r/LfK29V/1
英文:
You can use a lookahead pattern to assert that a match is followed by a character and the end of the line/string:
Search for:
(?=.$)
Replace with:
-
答案4
得分: 0
(?< = .)(?=.$)
或者匹配单个字符,然后在替换中使用完全匹配的字符,后跟“-”。
. (?=.$)
英文:
You are almost there, but you have to assert a character followed by the end of the string.
In the replacement use -
(?<=.)(?=.$)
Or match the single character and only use the lookahead. Then use the full match followed by -
in the replacement.
.(?=.$)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论