javascript - Javascript:在最后两个特定字符之间提取字符串
问题描述
我有字符串,其中每个单词后跟一个点,例如
示例 1:示例 2 I.love.watching.movies.
: hello.I.am.a.football.fan.
我想提取最后一个单词,然后是它的点,例如示例 2我想提取字符串fan.
如何实现这个?
解决方案
您可以使用String#match
.
let str = 'hello.I.am.a.football.fan.';
let res = str.match(/.*?\./g).pop();
console.log(res);
正则表达式的解释:
.*?
:匹配任何字符,除了行终止符,任意次数,懒惰。\.
: 匹配字符,.
.
推荐阅读
- ibm-datapower - 在 Datapower 中调用多个后端的单个请求
- java - Java8 流减少
- laravel - 切换按钮不执行操作
- azure - 如何为 azure vm 创建 TLS 证书?
- spring - Spring Boot 获取 aws s3 存储桶的大小
- python - cmake 无法识别 environ['PATH'] 中的汉字
- aws-lambda - Aws Lambda - 如何保留有效令牌以用于其他调用
- javascript - 在 insertRow 之后计算表行数
- java - 我如何在java中添加几秒钟的延迟
- xamarin.forms - 如何在 Xamarin iOS 上从 iCloud 获取带有 PHVideo 的视频?