Search code examples
regex-group

RegEx for google event


Hello I would like help writing a regex that captures all urls with the word confirmation in it.

Ex: https://example.com/this-is-a-confirmation

https://example.com/confirmation

https://example.com/folder/this-is-confirmation

I am trying to set up a Goal that captures all visits to any confirmation page on the website as by visiting that page you most likely filled out a form to download an asset

Thanks!


Solution

  • So, basically all links end with confirmation?

    Then you could just use a very stupid and simple regex like:

    confirmation$
    

    If you only want the URL to contain confirmation:

    confirmation
    

    is already enough (Demo). That's basically the same as if you were using String.endsWith(str) and String.contains(str).

    Depending on the way you're evaluating this, you may need to allow chars before the search term to produce a full match (not only a partial match):

    .*confirmation
    

    or

    .*confirmation.*
    

    if you want to allow any text after the search term.