问题
I have 3 type payment ( online, offline, by balance) every payment type have different url so I'm using regex for match all this url :
1- order/checkout/unpaid/done
2- order/checkout/paid/done?Authority=000000000000000000000000000039067905&Status=OK 3- order/checkout/paid/done?Status=OK
regex : (.*?)done
this regex match all of urls but the problem is it match some page too ! kile this product page :
/tork-doner-motahari-tehran
What is the solution ?
回答1:
You may use
(.*)done($|[?])
The point is that you need to match done at the end of the string or at the last ?. The pattern will match
(.*)- any 0+ characters, as many as possible, up to the last occurrence of the subsequent subpatternsdone- a literal substringdone($|[?])- either$(end of string anchor) or a literal?(can be written as\?in the pattern, the main point being that?without brackets or a\in front means 1 or 0 repetitions of the atom to the left of the?).
Note that you may turn the groups into non-capturing by adding ?: after ( if you are not using the capturing group values.
来源:https://stackoverflow.com/questions/44780839/how-to-exclude-some-url-from-a-regex-match