2

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 Answers1

2

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 subpatterns
  • done - a literal substring done
  • ($|[?]) - 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.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563