简体   繁体   English

正则表达式:如何反向搜索,获取所有字符,直到一个特定字符?

[英]Regex: How to search in reverse, obtaining all characters up to a specific character?

Say I have wordsandnumbers!morestuff!morelettersandnumbers , I want to get everything after the last ! 说我有wordsandnumbers!morestuff!morelettersandnumbers ,我想在最后一个之后得到所有东西! (meaning there may be more than 2 ! ). (意味着可能超过2个! )。 How can I do this using regex? 如何使用正则表达式执行此操作?

您可以使用$将正则表达式匹配项锚定到字符串的末尾,然后使用所有连续的非感叹号(直到该点为止):

[^!]*$

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

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