I’m currently trying to match and capture text in the following input:
field: one two three field: "moo cow" field: +this
I can match the field: with [a-z]*\: however I can’t seem to match the rest of the content so far my attempts have only resulted in capturing everything which is not what I want to do.
If you know that it is always going to be literally
field:there is absolutely no need for a regular expression:However, from your regex I assume that the name
fieldcan vary, as long as it’s in front of a colon. You could try to capture a word followed by:and then everything up to the next of those words (using a lookahead).An explanation of the regular expression:
So first we match
anylowercaseword:. And then we match one more character at a time, for each one checking that this character is not the start ofanotherlowercaseword:. With the capturing groups we can then later separately find the field’s name and the field’s value.