Learn business growth with Google Analytics 4 Forums Google Analytics 4 'RegEx: Table Variable is Undefined'

  • 'RegEx: Table Variable is Undefined'

    Posted by Noah on 4 May 2022 at 10:35 am

    Can’t figure out why this RegEx table variable isn’t doing its thing. I’m trying to find this string:

    _form_23 
    

    in this string for the Form Element:

    HTMLDivElement: html > body.customize-support#bg > div.page-wraper > div.page-content.bg-white > div.content-block#content-area > div.section-area.bg-gray > div.container > div.row.contact-bx-area2 > div.col-lg-8.col-md-12.wow.fadeIn.section-sp2 > div.form-area-box.ajax-form.p-lr30.p-sm-lr5 > div.row.placeani > div.col-lg-12 > div.form-white > div._form_23 > form._form._form_23._inline-form._dark#_form_64633F35D8028_ > div._form-thank-you
    

    _form_23 shows up twice in the Form Element string, regex validator says it’s all good, but the variable still says undefined.

    enter image description here

    I’m stumped. What’s going wrong?

    Here’s how I’ve set up my RegEx table variable:

    enter image description here

    Scarlett replied 11 months, 1 week ago 3 Members · 2 Replies
  • 2 Replies
  • Jaspreet

    Member
    18 June 2022 at 10:04 am

    Based on what’s included here, it’s possible that the issue might be occurring due to the regular expression not being correctly configured. It seems from your screenshot that you are using the regex validator in the text field of your variable configuration. This may only validate if the input matches the regular expression, rather than extracting the matches from the string. Ensure the configuration is correctly set to extract matches from your Form Element string. Furthermore, check how you are recalling your variable in your code, as this could also be a potential source of the issue. If possible, try to provide a little more context or code snippets for further clarification of the problem.

  • Scarlett

    Member
    13 January 2023 at 1:47 am

    The issue seems to lie in the set-up of your RegEx table variable. The first issue could be related to the ‘Input Variable’. The ‘Variable Type’ is ‘Page Path’ which may not be the correct location to find ‘_form_23’. Make sure to select the correct input source. The second issue could be with the matching pattern. You are using ‘^div._form\_23$’ which will look for ‘_form_23’ at the start or end of the string, and it must be exact. The characters ‘> div._form_23 >’ wouldn’t match this pattern, and if they are part of the string you are searching then they wouldn’t count as a match and the variable would appear as undefined. Change your regex pattern to ‘div._form\_23’ and ensure it is in the correct form and you should have a match.

Log in to reply.