Search code examples
regexpattern-matchingmatchimacros

Matching a string pattern which starts and ends with a string in imacros


Suppose This is my text

    SET abc "<select name="ctl00$ContentPlaceHolder1$ddlyear" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$ddlyear\',\'\')', 0)" id="ctl00_ContentPlaceHolder1_ddlyear" class="page-heading" style="background-color: rgb(255, 244, 244); width: 95px; outline: 1px solid blue;">    <option selected="selected" value="Select Year">Select Year</option>    <option value="2000">2000</option>   
<option value="2001">2001</option>   
<option value="2002">2002</option>  
<option value="2003">2003</option>   
<option value="2004">2004</option>
<option value="2005">2005</option>    
<option value="2006">2006</option>    
<option value="2007">2007</option>    
<option value="2008">2008</option>    
<option value="2009">2009</option>    
<option value="2010">2010</option>    
<option value="2011">2011</option>    
<option value="2012">2012</option>    
<option value="2013">2013</option>    
<option value="2014">2014</option>    
<option value="2015">2015</option>    
<option value="2016">2016</option>    
<option value="2017">2017</option>    
</select>"

And I just want to extract years from the above text, so I matched the staring string as <option value= and ending string as </option> and get the string between these two pattern

SET text EVAL("var s=\"{{abc}}\"; s.match(\"(?![<option value=])(.*)(?=</option>)\");")

But it gives the entire text again And if I do

SET text EVAL("var s=\"{{abc}}\"; s.match(\"(?![<option value=])(.*)(?=</option>)\");s[0]")

This gives me "<" Any suggestion where I'm going wrong? Thanks


Solution

  • I think you can try a simpler way like this:

    TAG XPATH="id('ctl00_ContentPlaceHolder1_ddlyear')" EXTRACT=TXTALL
    SET numbers EVAL("'{{!EXTRACT}}'.replace('Select Year[OPTION]', '');")
    PROMPT {{numbers}}