2

Hi there i have some problem with Regular Expressions I'm trying to set funnel goal with Regular Expressions

first step user come to changal.com and then search for near restaurant:

tehran/nezami-ganjavi

nezami-ganjavi in this url is neighborhood name and its different for each user based on their location.I have 400 neighborhood name

and then they go to restaurant page:

tehran/nezami-ganjavi/fastfood-charli-behjat-abad-tehran

I want to match the urls which ends with neighborhood name not restarunt page. for tracking funnel

  • Try `^tehran/([^/]+)$`. Please specify what is specific about neiborhood names so that a better regex can be devised. Are `-` always present there? – Wiktor Stribiżew Jun 27 '17 at 07:30
  • Then try `^tehran/([^/-]+-[^/]+)/?$` – Wiktor Stribiżew Jun 27 '17 at 07:36
  • @WiktorStribiżew thanks for helping yes always there is - . but your Regular Expressions does not work http://regexr.com/3g85p – Golhosseini Jun 27 '17 at 07:42
  • @WiktorStribiżew I just want to match the url for search result of near restaurant not restarunt page search result : https://changal.com/tehran/nezami-ganjavi the last part will change resto page : https://changal.com/tehran/nezami-ganjavi/fastfood-charli-behjat-abad-tehran – Golhosseini Jun 27 '17 at 07:45
  • You are not testing the patterns correctly. GA does not take the host part, it takes what goes after it. `tehran` will be the starting text. So, you need to test like this - http://regexr.com/3g85s. Note in GA there is no need escaping `/`. To test multiline string at regexr, you need to enable `m` modifier. Regexr uses JS regex, and GA uses RE2. In short: use appropriate tools, and test only in the target environment. Else, your "don't work" comment makes no sense. Try `^tehran/([^/-]+-[^/]+)/?$` or `^tehran/([^/]+)/?$` in GA. – Wiktor Stribiżew Jun 27 '17 at 07:46
  • @WiktorStribiżew Great it works thanks a lot now what should I do if I want math : kish/markaze-shahr too ? its another city I tried to use | but doesn't work thanks man – Golhosseini Jun 27 '17 at 08:04
  • Sorry, do you mean you need to match 2 cities (tehran and kish) or any city? If any city, replace `tehran` with `[^/]+`, else, try `^(tehran|kish)/([^/]+)/?$` Please let me know which pattern worked for you so that I could post and explain the solution. – Wiktor Stribiżew Jun 27 '17 at 08:06

1 Answers1

1

Note that GA regex parsing does not take into account the host part, it takes what goes after it. So, https://changal.com/ won;t be "visible" for it in https://changal.com/tehran/nezami-ganjavi.

Note in GA there is no need escaping /. You may use

^tehran/([^/-]+-[^/]+)/?$

or - if there is no need checking for an obligatory 1 hyphen in the neighborhood:

^tehran/([^/]+)/?$

or - to match any city:

^[^/]+/([^/]+)/?$

If your neighborhood value must have at least 1 hyphen, use

^[^/]+/([^/-]+-[^/]+)/?$

Some notes on the patterns:

  • ^ - start of string input
  • [^/]+ - one or more characters (+) that are not / (note that to match either tehran or kish you may use an alternation group (tehran|kish))
  • / - a slash
  • ([^/-]+-[^/]+) - 1+ chars other than / and - ([^/-]+), then a -, and then 1+ chars other than / ([^/]+)
  • /? - 1 or 0 slashes (an optional slash)
  • $ - end of string.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Thanks man yes both of them work at http://regexr.com but I tried to verify in GA and it said : This Goal would have a 0% conversion rate based on your data from the past 7 days and other thing i found some neighborhood name without - like : tehran/valfajr now we have 2 problem thanks man – Golhosseini Jun 27 '17 at 08:35
  • You will have to wait before you get enough data. ["You will need to wait a day for conversion rates to be non-zero, assuming you get actual conversion until then."](https://webmasters.stackexchange.com/a/69256). We don't have 2 problems. A correct regex for an appropriate problem means no problems at all. – Wiktor Stribiżew Jun 27 '17 at 08:36
  • I know this but these urls are working for 3 months ok lets see and what about second question ? match: tehran/valfajr without - thanks – Golhosseini Jun 27 '17 at 08:38
  • :) yes we don't have problem your advice works well but i forgot that we have non - utl too – Golhosseini Jun 27 '17 at 08:40
  • Look at `^[^/]+/([^/]+)/?$`, it is very generic. It will match a URL with `/ANY_NEIGHBORHOOD` – Wiktor Stribiżew Jun 27 '17 at 08:42
  • I asked another question here https://stackoverflow.com/questions/44780839/how-to-exclude-some-url-from-a-regex-match I would be happy if you answer it – Golhosseini Jun 27 '17 at 12:55