regexjmeterregex-lookaroundsregex-groupboost-regex

RegEx for extracting an attribute value


I am trying to extract the value of id from the code provided below

I have tried the following regular expression but it still comes back as my default value of : id_not_found

id" selectNOIOrg_do_frm_organization="(.+?)" />

<input type="radio" name="frm.organization" id="selectNOIOrg_do_frm_organization{C5DF28FD-26EF-90DA-1214-BD72E0214F17}" value="{C5DF28FD-26EF-90DA-1214-BD72E0214F17}" title="College of St. Jude" ext-ns-multiple="frmorganization">

I expect the regex extractor to be able to recognize the id (it is a dynamic id and changes based on the radio button selected)


Solution

  • Here, we might just want to take id=" as a left boundary and " as a right boundary, then collect our attribute value in the first capturing group $1:

    id="(.+?)"
    

    enter image description here

    DEMO

    Demo

    This snippet just shows that how the capturing groups work:

    const regex = /id="(.+?)"/gm;
    const str = `<input type="radio" name="frm.organization" id="selectNOIOrg_do_frm_organization{C5DF28FD-26EF-90DA-1214-BD72E0214F17}" value="{C5DF28FD-26EF-90DA-1214-BD72E0214F17}" title="College of St. Jude" ext-ns-multiple="frmorganization">
    `;
    let m;
    
    while ((m = regex.exec(str)) !== null) {
        // This is necessary to avoid infinite loops with zero-width matches
        if (m.index === regex.lastIndex) {
            regex.lastIndex++;
        }
        
        // The result can be accessed through the `m`-variable.
        m.forEach((match, groupIndex) => {
            console.log(`Found match, group ${groupIndex}: ${match}`);
        });
    }

    RegEx

    If this expression wasn't desired, it can be modified or changed in regex101.com.

    RegEx Circuit

    jex.im visualizes regular expressions:

    enter image description here