dimanche 8 mai 2016

RegEx: Finding match by negating (based on a missing string)

I've been googling a lot about this. What I'm trying to achive is the next: I have to check in a regex condition if a MIME is NOT of a specific type.

For example, I have recevied the next message: image/png, image/jpeg, document/pdf

I would like to detect the document/pdf part only , which is a MIME type, a string, that does NOT start with image/

But no matter how hard I looked, tried and played around with the RegExbody software, I just utterly fail to match it..

I'm posting this in despair and hopes that maybe an expert regex could help me out..

I tried many approaches, mainly: Finding out the non-image type, regardless if there is one or there isn't any image type.

It just refuses to work. I tried positive lookahead and negatvie lookahead. But I probably used it wrong somehow. I can't post the examples because I have tried and deleted so many. The one that seemed real close to working was \b(?:(?!image/\w+))\w+\b but it just persist on selecting the second part of the non-matching pattern. If I use: image/png It gets the: png Which means it would still return true although I meant it to ignore image/ types..

Aucun commentaire:

Enregistrer un commentaire