javascript - 从 JavaScript 中的字符串中删除正斜杠和前面的字符
问题描述
我的应用程序中有各种字符串,例如:
'0//France'
'1//Italy'
'4//Australia'
'1//Asia//Thailand'
'2//EMEA//Greece//Athens'
我想编写一个通用函数/正则表达式,它将上述字符串作为输入(一次一个)并返回以下内容:
France
Italy
Australia
Thailand
Athens
我怎样才能做到这一点?
解决方案
正则表达式很容易变得晦涩难懂,所以我建议使用基本String
函数:
const a = '2//EMEA//Greece//Athens';
// Find the last occurrence of `/` and return everything after it.
a.slice(a.lastIndexOf('/') + 1);
推荐阅读
- java - 更新对象 - SOAP API /Selenium Java
- macos - 由于 Kerberos 错误,连接失败(SQL Server 连接)
- javascript - 更新 JSON 对象数组的属性值 (React JS)
- database - 如何在flutter中存储每个用户的数据?
- html - QXmlQuery 无法使用 setQuery(QString) 将 xml 转换为 html
- git - gitk 不再显示差异。(本地更改已签入索引但未提交)
- javascript - for in 不减,但 for 减
- python - 将列表传递给Python中的查询
- python - 使用通配符查找多值子矩阵
- visual-studio - 使用 vs2019 编译内核驱动程序 USB 模板并针对 windows 7 时出错