Factfinder Posted January 22, 2014 Share Posted January 22, 2014 (edited) I have a file with the following content: <mokdjehspsksushshhhssssssss> line more lines <subject>: "something" line more lines<mnpmuksoelddldjdldjdlddjnyt> line more lines<kopksuusssssssssssshhhhdsr> line more lines <subject>: "something else" line more lines I have a script that reads the random heading from another file then reads the above file to find a pattern that matches the random characters then reads the string assigned to <subject>. This is my script: $str = '<mokdjehspsksushshhhssssssss>' $subject = StringRegExp(FileRead(@scriptdir & "\file"), $str & '.*\v*(?:.*\v*)+?\s*<subject>:\s*"(.*?)"', 1) If IsArray($subject) Then MsgBox(0,"", $subject[0]) Else MsgBox(0,"", "No Subject") EndIf The issue with the script: When the sections with random characters have corresponding <subject> the script works correctly. But in case there is no corresponding <subject> (like <mnpmuksoelddldjdldjdlddjnyt>, the second section in above example), the script reads the <subject> listed in the following section instead of returning no match. What I need is to match those random headings with the subject but stop matching at the next random heading. I have tried to use many combinations of (?![a-z]{20,}) before <subject> in the script with no success. Thank in advance. Edited January 23, 2014 by Factfinder Link to comment Share on other sites More sharing options...
Solution jchd Posted January 23, 2014 Solution Share Posted January 23, 2014 First, notice that StringRegExp doesn't read a file by itself: its first parameter is the subject string. Now try this pattern which works for me: (?s)<charactersequence>\R(?:.(?!<\w+>\R))*?<subject>:\s*"(.*?)" This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Factfinder Posted January 23, 2014 Author Share Posted January 23, 2014 Yes, I was creating an example and didn't include FileRead(), I edited my post. Your script works great. I guess one of the challenges was using single line mode. Thanks a lot. 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