-1

I use the regular expression attached but it works without adding the highlighted "ORG_40365", once I added "ORG_40365" it does not work. However, I need to specify the occurrence related to specific node and need to add "ORG_40365" at the end. Otherwise will return other value unexpected. Please click here to see the web_reg_save_param_regexp used

I cannot copy the code here as it does not allow me to save with error.

Code screenshot

I have the above string and want to save 9704 after tvNode_R-. However, the regular expression does not work.

Any help would be greatly appreciated!

user6496344
  • 1
  • 1
  • 3

1 Answers1

0

Foreward

Pattern Matching HTML can be rather difficult so it's generally recommended to use an HTML parsing tool.

Also I manually transcribed your photo of text. I recommend either replacing the photo with real text or inserting real text in addition to the photo.

Description

<tr(?=\s)(?=(?:[^>=]|=(?:'[^']*'|"[^"]*"|[^'"][^\s>]*))*?\sclass=['"]dxtlNode)(?=(?:[^>=]|=(?:'[^']*'|"[^"]*"|[^'"][^\s>]*))*?\sid=['"][^"]*tvNode_R-([0-9]{4}))(?:[^>=]|=(?:'[^']*'|"[^"]*"|[^'"\s]*))*\s?\/?>

Regular expression visualization

** To see the image better, simply right click the image and select view in new window

This regular expression will do the following:

  • find tr tags
  • require the tr tag to have an class dxtlNode
  • require the tr tag to have an id with tvNode_R- followed by 4 digits
  • Captures the 4 digits identified above into Capture Group 1
  • Capture the entire opening tr tag into Capture Group 0
  • Avoids some difficult edge cases which makes pattern matching in HTML difficult

Example

Live Demo

https://regex101.com/r/gK5dM0/1

Sample text

<td class="dxtlHSEC"></td></tr><tr id="m_m_splitMaster_P_TC_p_n_tvNode_R-9704" 
class="dxtlNode" oncontextmenup="return aspxTLMenu(&#39;m_m_splitMaster_P_TC_p_n_tvNode&#39;,&#39;Node&#39;,&#39;;9704&#39;,event)">
<span class="btxt">ORG_40365</span></td><td class="dstlHSEC"></td></tr>

Sample Matches

Capture Group 0.    [31-211]  `<tr id="m_m_splitMaster_P_TC_p_n_tvNode_R-9704" class="dxtlNode" oncontextmenup="return aspxTLMenu(&#39;m_m_splitMaster_P_TC_p_n_tvNode&#39;,&#39;Node&#39;,&#39;;9704&#39;,event)">`
Capture Group 1.    [73-77]   `9704`

Explanation

NODE                     EXPLANATION
----------------------------------------------------------------------
  <tr                      '<tr'
----------------------------------------------------------------------
  (?=                      look ahead to see if there is:
----------------------------------------------------------------------
    \s                       whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
  )                        end of look-ahead
----------------------------------------------------------------------
  (?=                      look ahead to see if there is:
----------------------------------------------------------------------
    (?:                      group, but do not capture (0 or more
                             times (matching the least amount
                             possible)):
----------------------------------------------------------------------
      [^>=]                    any character except: '>', '='
----------------------------------------------------------------------
     |                        OR
----------------------------------------------------------------------
      =                        '='
----------------------------------------------------------------------
      (?:                      group, but do not capture:
----------------------------------------------------------------------
        '                        '\''
----------------------------------------------------------------------
        [^']*                    any character except: ''' (0 or more
                                 times (matching the most amount
                                 possible))
----------------------------------------------------------------------
        '                        '\''
----------------------------------------------------------------------
       |                        OR
----------------------------------------------------------------------
        "                        '"'
----------------------------------------------------------------------
        [^"]*                    any character except: '"' (0 or more
                                 times (matching the most amount
                                 possible))
----------------------------------------------------------------------
        "                        '"'
----------------------------------------------------------------------
       |                        OR
----------------------------------------------------------------------
        [^'"]                    any character except: ''', '"'
----------------------------------------------------------------------
        [^\s>]*                  any character except: whitespace
                                 (\n, \r, \t, \f, and " "), '>' (0 or
                                 more times (matching the most amount
                                 possible))
----------------------------------------------------------------------
      )                        end of grouping
----------------------------------------------------------------------
    )*?                      end of grouping
----------------------------------------------------------------------
    \s                       whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
    class=                   'class='
----------------------------------------------------------------------
    ['"]                     any character of: ''', '"'
----------------------------------------------------------------------
    dxtlNode                 'dxtlNode'
----------------------------------------------------------------------
  )                        end of look-ahead
----------------------------------------------------------------------
  (?=                      look ahead to see if there is:
----------------------------------------------------------------------
    (?:                      group, but do not capture (0 or more
                             times (matching the least amount
                             possible)):
----------------------------------------------------------------------
      [^>=]                    any character except: '>', '='
----------------------------------------------------------------------
     |                        OR
----------------------------------------------------------------------
      =                        '='
----------------------------------------------------------------------
      (?:                      group, but do not capture:
----------------------------------------------------------------------
        '                        '\''
----------------------------------------------------------------------
        [^']*                    any character except: ''' (0 or more
                                 times (matching the most amount
                                 possible))
----------------------------------------------------------------------
        '                        '\''
----------------------------------------------------------------------
       |                        OR
----------------------------------------------------------------------
        "                        '"'
----------------------------------------------------------------------
        [^"]*                    any character except: '"' (0 or more
                                 times (matching the most amount
                                 possible))
----------------------------------------------------------------------
        "                        '"'
----------------------------------------------------------------------
       |                        OR
----------------------------------------------------------------------
        [^'"]                    any character except: ''', '"'
----------------------------------------------------------------------
        [^\s>]*                  any character except: whitespace
                                 (\n, \r, \t, \f, and " "), '>' (0 or
                                 more times (matching the most amount
                                 possible))
----------------------------------------------------------------------
      )                        end of grouping
----------------------------------------------------------------------
    )*?                      end of grouping
----------------------------------------------------------------------
    \s                       whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
    id=                      'id='
----------------------------------------------------------------------
    ['"]                     any character of: ''', '"'
----------------------------------------------------------------------
    [^"]*                    any character except: '"' (0 or more
                             times (matching the most amount
                             possible))
----------------------------------------------------------------------
    tvNode_R-                'tvNode_R-'
----------------------------------------------------------------------
    (                        group and capture to \1:
----------------------------------------------------------------------
      [0-9]{4}                 any character of: '0' to '9' (4 times)
----------------------------------------------------------------------
    )                        end of \1
----------------------------------------------------------------------
  )                        end of look-ahead
----------------------------------------------------------------------
  (?:                      group, but do not capture (0 or more times
                           (matching the most amount possible)):
----------------------------------------------------------------------
    [^>=]                    any character except: '>', '='
----------------------------------------------------------------------
   |                        OR
----------------------------------------------------------------------
    =                        '='
----------------------------------------------------------------------
    (?:                      group, but do not capture:
----------------------------------------------------------------------
      '                        '\''
----------------------------------------------------------------------
      [^']*                    any character except: ''' (0 or more
                               times (matching the most amount
                               possible))
----------------------------------------------------------------------
      '                        '\''
----------------------------------------------------------------------
     |                        OR
----------------------------------------------------------------------
      "                        '"'
----------------------------------------------------------------------
      [^"]*                    any character except: '"' (0 or more
                               times (matching the most amount
                               possible))
----------------------------------------------------------------------
      "                        '"'
----------------------------------------------------------------------
     |                        OR
----------------------------------------------------------------------
      [^'"\s]*                 any character except: ''', '"',
                               whitespace (\n, \r, \t, \f, and " ")
                               (0 or more times (matching the most
                               amount possible))
----------------------------------------------------------------------
    )                        end of grouping
----------------------------------------------------------------------
  )*                       end of grouping
----------------------------------------------------------------------
  \s?                      whitespace (\n, \r, \t, \f, and " ")
                           (optional (matching the most amount
                           possible))
----------------------------------------------------------------------
  \/?                      '/' (optional (matching the most amount
                           possible))
----------------------------------------------------------------------
  >                        '>'
----------------------------------------------------------------------
Ro Yo Mi
  • 14,790
  • 5
  • 35
  • 43
  • The user is engaged in performance test with the tool LoadRunner so the parsing needs to be in context with the execution of a virtual user, capturing a value sent back from the server for reuse later in the same test. Using an external HTML parsing tool manually is not going to be possible in this context – James Pulley Jun 22 '16 at 13:33
  • Thanks, not sure how I can add the attachment. Cannot use web_reg_save_param as there are multiple occurrences for the boundary, need to match certain pattern. – user6496344 Jun 22 '16 at 16:06
  • Consider the use of an ordinal to pick up the appropriate nth instance – James Pulley Jun 22 '16 at 19:22