Madness Posted July 12, 2010 Share Posted July 12, 2010 I need to search for a heading in a text file and delete everything from the beginning of the file to the heading. Is there coding in regular expressions to do this? I see some REs support ^^ as the beginning of a file. Or should I be doing this a different way. I'm reading the contents of a file using FileRead into a variable, then working on the variable, and writing this back to a file. I need to run numerous globals on this, plus remove some items.Also, are there limits to the amount of text using FileRead that can be read into a string variable? Link to comment Share on other sites More sharing options...
Madness Posted July 12, 2010 Author Share Posted July 12, 2010 (edited) Looks like this does the trick: (?s)(?m)^.*search item Still would like to know if there are any limits in the file size that can be read with FileRead though. Edited July 12, 2010 by Madness Link to comment Share on other sites More sharing options...
GEOSoft Posted July 12, 2010 Share Posted July 12, 2010 $sStr = stringRegExpReplace(FileRead("somefile.txt"), "(?i)(?s)^.*?(search string.*)$", $1) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted July 12, 2010 Share Posted July 12, 2010 I wrote a function that behaves like string split except the deliminator is a regular expression.You will just need to query the resulting array for what you want.expandcollapse popup#include <Array.au3> ;~ ---for example $sString="abc124bcd2cde3def4efg" $sRegExp="[0-9]" $aResult=_REsplit($sString,$sRegExp) _arraydisplay($aresult) $sRegExp="124" $aResult=_REsplit($sString,$sRegExp) _arraydisplay($aresult) $sRegExp="[cd]" $aResult=_REsplit($sString,$sRegExp) _arraydisplay($aresult) ;~------ Func _RESplit($sString, $sRegExp, $iRegExBehave=3 ) Local $aReturn[1] $aReturn[0]=$sRegExp $aSplits = StringRegExp($sString, $sRegExp,$iRegExBehave) For $x = 0 To UBound($aSplits) - 1 if StringInStr($sString, $aSplits[$x]) then $iLeft = StringInStr($sString, $aSplits[$x])-1 $iRight = StringLen($sString)-($iLeft+stringlen($aSplits[$x])) _ArrayAdd($aReturn, StringLeft($sString, $iLeft)) $sString = StringRight($sString, $iRight) EndIf Next _ArrayAdd($aReturn, $sString) Return($aReturn) EndFunc ;==>_RESplit Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
Madness Posted July 13, 2010 Author Share Posted July 13, 2010 $sStr = stringRegExpReplace(FileRead("somefile.txt"), "(?i)(?s)^.*?(search string.*)$", $1)Thanks George. I really like your Toolkit. Nice job! Link to comment Share on other sites More sharing options...
GEOSoft Posted July 13, 2010 Share Posted July 13, 2010 You're welcome and thanks for the comment about the toolkit. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now