javascript - Trying to come up with Regex Expression
问题描述
I am trying to parse this string: *(!((stunned)||dead))
Currently have
// ["*", "!", "stunned", "||dead"]
string.match(/[^()]+/g)
Trying to get
["*", "!", "stunned", "||", "dead"]
Ideally in a way that would also separate it regarless of placement "||dead"
or "dead||"
while support ||, &&, ==
解决方案
Perhaps you want to either match word characters, or non-word characters which are not parentheses:
const str = '*(!((stunned)||dead))';
console.log(str.match(/\w+|[^()\w]+/g));
推荐阅读
- r - 我想在 R 中找到行位置
- python - discord.py 中的打字机
- php - 是否可以同时创建 SQL 表和插入数据?
- sql - 如何在实体框架mvc c#中正常运行查询脚本
- xamarin.forms - 客户和显示文件 pdf xamarin 表格
- java - java.net.SocketException:连接重置“”“
- c# - 如何使用 LINQ C# 将一个数据表拆分为两个(匹配记录)(不匹配记录)
- ios - 无法加载文件列表的内容:'/Target Support Files/Pods-Salotime/Pods-Salotime-frameworks-Debug-input-files.xcfilelist'
- docker - Docker 证书已过期或尚未生效
- typescript - 如何设置类型取决于打字稿中的函数参数?