我需要一个正则表达式的帮助,它将在一行中获得模式的最后一个实例.
有问题的行用以下模式编写(用斜杠分隔):
/this/is/how/it/looks/
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,我希望得到looks输出.
请注意,这些行不均匀,并且可以包含比示例更少或更多的字符串.
/it/can/be/shorter/
/it/can/also/be/longer/than/most/lines/
Run Code Online (Sandbox Code Playgroud)
对于上述行,我期望能获得shorter和lines分别.
/([^/]*)/$
Run Code Online (Sandbox Code Playgroud)
是你需要的正则表达式.
说明:
/ # Match a slash
( # Start capturing group number 1
[^/]* # Match any number of characters except slashes
) # End capturing group number 1
/ # Match a slash
$ # Match the position at the end of the string
Run Code Online (Sandbox Code Playgroud)
在regex101.com上测试它.
| 归档时间: |
|
| 查看次数: |
279 次 |
| 最近记录: |