I’m trying to match a string like this:
key:value
But not match strings like these:
"has: stuff"
("or: that")
So far I’ve got a regex that looks like this:
^(.*?):
This is matching the all of these examples.
How can I prevent this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In your counterexamples, what are the factors that make them “invalid” for the purposes of this match? Is it the punctuation at the start? The space after the colon?
It sounds like you should just include what you want, rather than trying to exclude what you don’t. If your key/value pairs always consist of alphanumeric keys (i.e. no punctuation), then you can use a regex that simply looks for that.