regex - 用于匹配以部分已知终止符结尾的未知长度字符串的正则表达式

标签 regex

我目前正在尝试编写一个正则表达式,它将仅提取分配给 state: 标记的值,而不考虑除标题之外的其他参数的顺序。

例如:

addcard "My card title" assigned: @username @username2 state: ready to
deploy due: Next Wednesday project: tooling #tag1 #tag2 #tag3

addcard "My card title" state:ready to deploy assigned: @username 
@username2 due: Next Wednesday project: tooling #tag1 #tag2 #tag3

addcard "My card title" #tag1 #tag2 #tag3 state: ready to deploy 
assigned: @username @username2 due: Next Wednesday project: tooling 

应该全部返回:ready to deploy or state:ready to deploy or state: ready to deploy

我尝试过使用负查找,但我开始觉得我可能对负查找理解不够透彻。

我当前的正则表达式:regex101

最佳答案

尝试这样的事情:

状态:([\w\s]+)\s

https://regex101.com/r/b4Xw92/1

关于regex - 用于匹配以部分已知终止符结尾的未知长度字符串的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41455733/

相关文章:

python - 具有 5 个数字或 IND/5 个数字的字符串的正则表达式

php - 使用 Regex、PHP 或 Javascript 搜索链接并识别 RSS 源

php -\\x80-\\xFF 指的是什么?

javascript - 正则表达式不匹配结果

Python-第二次重复时删除一个字符

javascript - RegExp,JavaScript : Break string at specified characters,对其进行编码,并将其插入回同一位置

regex - 匹配法语字符

html - HTML 表单的 'minimum of 5 characters' 的正则表达式模式

javascript - 使用 Javascript 提取简单字符串的一部分

regex - 将 inputText 值限制为仅字母字符