简体   繁体   中英

[^Z]+ what does this mean in Regex (Python)?

[^Z]+slogan: "([^"]*) What does this mean in Regex (Python)? It returns "Life is a trip"

In this portion code:

< 0,byc:0,owlid:"cf",barca Ztry{if (!window.Cloud) {var Cloud=[{verbose:0,p:0,byc:0,owlid:"cf",bag2:1,mirage2:0,oracle:0,paths:{cloud:"/cbcex-cmi/nexp/dok7v=02fcfa4f56, slogan: "Life is too short"
name="description" content="scream your longs out now." 
name="description slogan: "Life is a trip" selling real estate />

screenshot of matching http://imageshack.com/a/img607/3699/5l2n.png

I'm trying to understand why isn't it returning "Life is too short", the 1st instance of slogan: " .....??? ?

What it returns is in GREEN, NOT YELLOW. Note there are 2 instances of slogan: " in the code, why doesn't it choose the 1st one and return "Life is too short"? Still confused.

Thank You!

Edit: normally the regex returns the max length coincidence, in this case it doesn't return " ... life is too short" because it can return something longer

First: [^Z]+ = "Every character except Z, at least once (1 times or more)"

Then it finds = slogan: '

and end with [^'] = "Every character except ' 0 times or more"

The result it's something like: (some characters but not Z) slogan:" (other characters or none, but not ")

That's why it start after the Z, and finishes before the " (after slogan: " )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM