python regex token capture
Question: I need to capture small code (token) from html with regex, I'm writing code
with BeautifulSoup but it is not possible to compile with py2exe, so for this
I need a solution wihth regex. My html code is this:

    
    
    <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="http://localhost/wp-admin/update.php?action=upload-plugin">
            <input type="hidden" id="_wpnonce" name="_wpnonce" value="a7a9167537"><input type="hidden" name="_wp_http_referer" value="/wp-admin/plugin-install.php?tab=upload">     <label class="screen-reader-text" for="pluginzip">Plugin zip file</label>
            <input type="file" id="pluginzip" name="pluginzip">
            <input type="submit" name="install-plugin-submit" id="install-plugin-submit" class="button" value="Install Now" disabled="">    </form>
    

and I need to capture this code: `a7a9167537`

I wrote this regex but it did not work:

    
    
    id="_wpnonce" name="_wpnonce" value="(.*)"
    


Answer: Try :

    
    
        import re
        searchText = '<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="http://localhost/wp-admin/update.php?action=upload-plugin"><input type="hidden" id="_wpnonce" name="_wpnonce" value="a7a9167537"><input type="hidden" name="_wp_http_referer" value="/wp-admin/plugin-install.php?tab=upload">     <label class="screen-reader-text" for="pluginzip">Plugin zip file</label><input type="file" id="pluginzip" name="pluginzip"><input type="submit" name="install-plugin-submit" id="install-plugin-submit" class="button" value="Install Now" disabled="">    </form>'
    
    
        print re.sub("(.+name=\"_wpnonce\"\\ value=\"([\\d\\w]{10})\">.+)", "\\2", searchText)
    

