Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to match a unknown length string ending in partially known terminator

Tags:

regex

I am currently trying to write a regular expression that will extract only the value assigned to the state: tag irrespective of the order of the other arguments excluding the title.

For example:

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 

Should all return: ready to deploy or state:ready to deploy or state: ready to deploy

I tried my luck at using a negative lookup , but I'm starting to think I may not understand negative lookups well enough.

My current regular expression: regex101


1 Answers

Try something like:

state:([\w\s]+)\s

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

like image 121
Jack Avatar answered Oct 23 '25 00:10

Jack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!