face Posted May 31, 2014 Share Posted May 31, 2014 i have this script, it copies and saves all lines starting with the word "valuable" how can i make it copy and save all lines starting with any character? #include <File.au3> #include <Array.au3> $file_output = @DesktopDir & "\output.txt" Local $mypath = @ScriptDir, $lines = "" Local $aFiles = _FileListToArrayRec($mypath, "*.txt", 1, 1, 0, 2) For $i = 1 to $aFiles[0] $content = FileRead($aFiles[$i]) $res1 = StringRegExp($content, '(?m)^(valuable\N*)\R?', 3) If IsArray($res1) Then $lines &= $aFiles[$i] & @CRLF $lines &= _ArrayToString($res1, @CRLF) & @CRLF & @CRLF EndIf Next FileWrite($file_output, $lines) Link to comment Share on other sites More sharing options...
czardas Posted May 31, 2014 Share Posted May 31, 2014 (edited) Try altering the regexp: '(?m)^(' & $sMyLetter & '\N*)\R?' I can't test it ATM - unfortunately. A word of warning: some characters have special significance in regexp patterns. The code should work for alphanumeric input. Regexp is also case sensitive. The following change makes the pattern case insensitive. '(?i)(?m)^(' & $sMyLetter & '\N*)\R?' Substitute the regexp into the code you have. Declare the variable $sMyLetter and assign it equal to the character you are looking for. Run the code and see what happens. Edited May 31, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
face Posted May 31, 2014 Author Share Posted May 31, 2014 thanks alot that works for 1 letter at a time. how can i make it work with (-, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0) at once Link to comment Share on other sites More sharing options...
mikell Posted May 31, 2014 Share Posted May 31, 2014 (edited) '(?im)^([\d-]\N*)\R?' This will work for lines starting with hyphen or any digit For easier use you should build a little func with the desired pattern as parameter $aLines = _LinesStartingWith($txt, '[\d-]') Func _LinesStartingWith($content, $sMyPattern) $res = StringRegExp($content, '(?m)^(' & $sMyPattern & '\N*)\R?', 3) If not IsArray($res) Then Return SetError(0) Return $res EndFunc Edited May 31, 2014 by mikell 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