kylomas Posted March 1, 2015 Share Posted March 1, 2015 (edited) I'm trying to populate $title with whatever is on the line containing "#title#". These tries are blanking out everything preceding #title# on that line and returning all other lines. #include <array.au3> ;#title# the title of this code local $str = fileread(@ScriptFullPath) ;local $title = stringregexpreplace($str,'(?i).*?\#title\#(.+).*', '$1') ;local $title = stringregexpreplace($str,'(?im).*?\#title\#(.+).*', '$1') ;local $title = stringregexpreplace($str,'(?im)^.*?\#title\#(.+).*$', '$1') ;local $title = stringregexpreplace($str,'(?im)^.*?\#title\#(.+\R).*$', '$1') local $title = stringregexpreplace($str,'(?im)\#title\#(.+)', '$1') ConsoleWrite(@error & ' - ' & @extended & ' - ' & $title & @CRLF) _arraydisplay($title) exit How can I return whatever follows #title# on that line only? kylomas more tries ;local $title = stringregexpreplace($str,'(?im).*?\#title\#(.+)$.*', '$1') local $title = stringregexpreplace($str,'(?im).*?\#title\#(.+).*$', '$1') I'm lost... Edited March 1, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jchd Posted March 1, 2015 Share Posted March 1, 2015 local $title = stringregexp($str, '(?im)\#title\#(.+)', 1) Aren't you making your life difficult? 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...
kylomas Posted March 1, 2015 Author Share Posted March 1, 2015 Hi jchd, been awhile... I can get SRE to return the correct results all day long, can't figure out the SRER part... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted March 1, 2015 Share Posted March 1, 2015 Not very clear... do you want this ? #include <array.au3> ;#title# the title of this code local $str = fileread(@ScriptFullPath) local $title = stringregexpreplace($str, '(?s).*?#title#\s*(\N+).*', '$1') Msgbox(0,"", $title) Link to comment Share on other sites More sharing options...
kylomas Posted March 1, 2015 Author Share Posted March 1, 2015 mikell, Thanks, that did it, now to try to understand it... How is this How can I return whatever follows #title# on that line only? not clear? Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted March 1, 2015 Share Posted March 1, 2015 Please don't care, the antislashes everywhere in #title# caused me trouble N matches anything except newline, so in (N+).* the engine stops backreferencing at the first newline encountered and .* is the whole rest of the string Anyway jchd is right, the new array feature allows to get the expected string immediately and it's much easier local $title = stringregexp($str, '#title#\s*(\N+)', 1)[0] Link to comment Share on other sites More sharing options...
kylomas Posted March 1, 2015 Author Share Posted March 1, 2015 Yea, I was going to give up and go with that except that the title may or may not appear...thanks for your help! Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jguinch Posted March 1, 2015 Share Posted March 1, 2015 (edited) You can also cheat to get an empty capture on failure : $title = stringregexp($str, '#title#(\N+)|()$', 1)[0]) I don't know if it's a good idea, but it works and can be useful sometimes. Edited March 1, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF 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