Search code examples
javascriptregexmatchevalimacros

Extract value by regular expression by using imacros eval


I get the following result after using this code TAG POS=2 TYPE=a ATTR=class:stop-propagation&&TXT:* EXTRACT=HTM

Output

<a class="stop-propagation" href="javascript:void(0);" data-link="/propertyDetails/poiOnMap.html?lat=19.2412011&amp;longt=73.1290596&amp;projectOrProp=Project&amp;city=Thane&amp;includeJs=y&amp;type=poiMap2017&amp;address=Thane, Maharashtra" id="map_link_27696295" onclick="stopPage=true; showPhotoMap('/propertyDetails/poiOnMap.html?lat=19.2412011&amp;longt=73.1290596&amp;projectOrProp=Project&amp;city=Thane&amp;includeJs=y&amp;type=poiMap2017&amp;address=Thane, Maharashtra');" style="outline: 1px solid blue;"><span class="icoMap"></span>Map</a>

I 'm trying to extract value for the variable called longt from the following code

SET longt EVAL("'{{!EXTRACT}}'.match(/&(longt=.+?)&/)[1];")
PROMPT "{{longt}}"

But this is not giving me any output. any suggestions on what modifications could be done to get the output, will be helpful for me. Thanks


Solution

  • You can try this regex:

    longt=(\d+(?:\.\d+)?)
    

    Regex Demo

    You can try this in imacro:

    SET longt EVAL("var regex = /longt=(\\d+(?:\\.\\d+)?)/g; var str = '{{!EXTRACT}}';str.match(regex);")
    PROMPT {{longt}}