Search code examples
regextimeloadrunner

Regular extracting only time from the string


Below is the string:

id='PMN_PRCSLIST_BEGINDTTM'>06/13/2018&nbsp; 6:35:00AM EDT</span>

From which i want to extract 6:35:00AM.
How do i achieve it using loadrunner?
I have tried doing:

id='PMN_PRCSLIST_BEGINDTTM'>(\\d:\\d\\d:\\d\\dAM)</span>"

But it did not helped me.


Solution

  • You may add .* to match any chars in between > and the time, and between AM and <:

    id='PMN_PRCSLIST_BEGINDTTM'>.* (\\d\\d?:\\d\\d:\\d\\d[AP]M).*</span>
    

    Note you should add a space after the first .* since you may have 2 digits in the hour part and to match 1 or 2, you need \d\d?. To match PM or AM, use [PA]M.

    Note that if the space before the time is optional, use lazy dot after >:

    id='PMN_PRCSLIST_BEGINDTTM'>.*?(\\d\\d?:\\d\\d:\\d\\d[AP]M).*</span>
                                  ^ 
    

    See the regex demo

    Besides, if you want to stay within 1 tag value, replace .* with [^<]*.