regex - Vbscript to Extract Data between two Keywords with RegExp -


i want extract block of data between 2 keywords :#start , :#end

so have file contains:

xxxxxxxxx

yyyyyyyyyyyyy ...........

:#start

extracting data block ...................
:#end

zzzzzzzzzzzzzzzzzzzzzzzzzzzzz

pppppppppppppppppppppppppppppppp

so how can in vbscript using regexp ?

ok , solved : explain little why want extract data :

so have batch file contains hta file extracted it, put hta code between :#start :#end

some code of batch file :

@echo off  :#start <html> <head> <title>password entry</title> <hta:application id="htaid" applicationname="password" border="thin" icon="wlrmdr.exe" borderstyle="normal" caption="yes" contextmenu="no" maximizebutton="no" minimizebutton="yes" navigable="yes" showintaskbar="yes" singleinstance="yes" sysmenu="yes" scroll="no"  showintaskbar="yes"    selection="no" minimizebutton="no"  > </head> <meta http-equiv="msthemecompatible" content="yes">  <body topmargin="1" leftmargin="1"><center><div><span id="onscr"></span></div></center></body> <script language="vbscript"> '--------------------------------------------------------------------------------------- sub window_onload     centerwindow 250,150     call passwordform()     call textfocus() end sub '--------------------------------------------------------------------------------------- sub centerwindow(x,y)     dim ileft,itop     window.resizeto x,y     ileft = window.screen.availwidth/2 - x/2     itop = window.screen.availheight/2 - y/2     window.moveto ileft,itop end sub '---------------------------------------------------------------------------------------- sub savebatch()     set fs=createobject("scripting.filesystemobject")     strfile=fs.getabsolutepathname(fs.buildpath(fs.getspecialfolder(2), "userin.bat"))     set ts=fs.opentextfile(strfile,2,true)     if passwordarea.value <> ""         ts.writeline "set password="& passwordarea.value         ts.close         self.close 'to close hta after saving password variable userin.bat     else         msgbox "the password entry empty ! "& vbcrlf & "please type again passowrd",vbexclamation,"the password entry"         location.reload(true) 'to reload hta again     end if end sub '---------------------------------------------------------------------------------------- sub passwordform()     self.document.title = "my password enrty"     self.document.bgcolor = "#bbbfff"     onscr.innerhtml="<center><font color=""#ffffff"" size=""+1"" face=""verdana,arial,helvetica,sans-serif"">password entry</font<br>"_     &"<input type=""password"" name=""passwordarea"" size=""20"" onkeyup=""textfocus""><p>"_     &"<input type=""submit"" style=""height:25;width:110"" value=""ok"" onclick=""savebatch"">" end sub '---------------------------------------------------------------------------------------- sub textfocus     passwordarea.focus  end sub '---------------------------------------------------------------------------------------- </script> </body> </html> :#end ::*********************************************************************************************** :myvbs ::'********************************************************************************************** 

the vbs file :

 set fso = createobject("scripting.filesystemobject")  set f=fso.opentextfile("htabatchvbscript.bat",1)  a=f.readall  set r=new regexp  r.global = true  r.multiline = true  r.ignorecase = true  r.pattern = "(?:^|(?:\r\n))(?::#start\r\n)([\s\s]*?)(?:\r\n)(?::#end)"  set matches = r.execute(a)  if matches.count > 0 data = matches(0).submatches(0)  msgbox data  writefiletext "test.hta",data  f.close '********************************************************************************************** function writefiletext(sfile,data)      dim objfso,ots,stext      set objfso = createobject("scripting.filesystemobject")      set ots = objfso.createtextfile(sfile,2)      ots.writeline data      ots.close      set ots = nothing      set objfso = nothing  end function  

i have finished writing batch generate hta box hide password in commandline , want share :

@echo off title generate hta box hide password in commandline copyright hackoo 2014 mode con cols=80 lines=5 & color 9b set myvbsfile=%tmp%\%~n0.vbs set myhtafile=%tmp%\%~n0.hta call :createmyvbs cscript.exe //nologo %myvbsfile% start /wait mshta.exe "%myhtafile%" del "%myvbsfile%" & del "%myhtafile%" /f "tokens=*" %%i in (%tmp%\userin) set "mypassword=%%i" echo password : %mypassword% del %tmp%\userin pause  :#start <html> <head> <title>password entry</title> <hta:application id="htaid" applicationname="password" border="thin" icon="wlrmdr.exe" borderstyle="normal" caption="yes" contextmenu="no" maximizebutton="no" minimizebutton="yes" navigable="yes" showintaskbar="yes" singleinstance="yes" sysmenu="yes" scroll="no"  showintaskbar="yes"    selection="no" minimizebutton="no"  > </head> <meta http-equiv="msthemecompatible" content="yes">  <body topmargin="1" leftmargin="1"><center><div><span id="onscr"></span></div></center></body> <script language="vbscript"> '--------------------------------------------------------------------------------------- sub window_onload     centerwindow 250,150     call passwordform()     call textfocus() end sub '--------------------------------------------------------------------------------------- sub centerwindow(x,y)     dim ileft,itop     window.resizeto x,y     ileft = window.screen.availwidth/2 - x/2     itop = window.screen.availheight/2 - y/2     window.moveto ileft,itop end sub '---------------------------------------------------------------------------------------- sub savebatch()     set fs=createobject("scripting.filesystemobject")     strfile=fs.getabsolutepathname(fs.buildpath(fs.getspecialfolder(2),"userin"))     set ts=fs.opentextfile(strfile,2,true)     if passwordarea.value <> ""         ts.writeline passwordarea.value         ts.close         self.close 'to close hta after saving password variable userin.bat     else         msgbox "the password entry empty ! "& vbcrlf & "please type again passowrd",vbexclamation,"the password entry"         location.reload(true) 'to reload hta again     end if end sub '---------------------------------------------------------------------------------------- sub passwordform()     self.document.title = "my password enrty"     self.document.bgcolor = "lightblue"     onscr.innerhtml="<center><font color=""#ffffff"" size=""+1"" face=""verdana,arial,helvetica,sans-serif"">password entry</font<br>"_     &"<input type=""password"" name=""passwordarea"" size=""20"" onkeyup=""textfocus""><p>"_     &"<input type=""submit"" style=""height:25;width:110"" value=""ok"" onclick=""savebatch"">" end sub '---------------------------------------------------------------------------------------- sub textfocus     passwordarea.focus  end sub '---------------------------------------------------------------------------------------- </script> </body> </html> :#end ::*********************************************************************************************** :createmyvbs ::'********************************************************************************************** ( echo. set fso = createobject^("scripting.filesystemobject"^) echo. set f=fso.opentextfile^("%~f0",1^) echo. a=f.readall echo. set r=new regexp echo. r.pattern = "(?:^|(?:\r\n))(?::#start\r\n)([\s\s]*?)(?:\r\n)(?::#end)" echo. set matches = r.execute^(a^) echo. if matches.count ^> 0 data = matches^(0^).submatches^(0^) echo. writefiletext "%myhtafile%",data echo. f.close ::'********************************************************************************************** echo.  echo. function writefiletext^(sfile,data^) echo.     dim objfso,ots,stext echo.     set objfso = createobject^("scripting.filesystemobject"^) echo.     set ots = objfso.createtextfile^(sfile,2^) echo.     ots.writeline data echo.     ots.close echo.     set ots = nothing echo.     set objfso = nothing echo. end function  ) > %myvbsfile% ::'*********************************************************************************************** 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -