HurleyShanabarger Posted June 21, 2016 Share Posted June 21, 2016 Hello, I have the following kind of data: |Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Want[0]|0|Decimal|6|9999.9| |Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Want0|Decimal|6|9999.9| |Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Wan|Decimal|6|9999.9| What I want to retrieve with the regular expression is this: This.I.Want[0] This.I.Want0 This.I.Wan I am using this code, but the result is not what I have expected... StringRegExp($Value, "(This.*)\|", 3) [0] = This.I.Want[0]|0|Decimal|6|9999.9 [1] = This.I.Want0|Decimal|6|9999.9 [2] = This.I.Wan|Decimal|6|9999.9 Link to comment Share on other sites More sharing options...
jchd Posted June 21, 2016 Share Posted June 21, 2016 Try this: #include <Array.au3> #include <String.au3> Local $value = _ "|Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Want[0]|0|Decimal|6|9999.9|" & @CRLF & _ "|Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Want0|Decimal|6|9999.9|" & @CRLF & _ "|Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Wan|Decimal|6|9999.9|" & @CRLF Local $a = StringRegExp($Value, "(?i)Input/output\|[^|]*\|([^|]*)\|", 3) _ArrayDisplay($a) 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...
ViciousXUSMC Posted June 21, 2016 Share Posted June 21, 2016 Looks good to me except the non escaped "/" between input and output. Link to comment Share on other sites More sharing options...
jchd Posted June 21, 2016 Share Posted June 21, 2016 Why do you want to escape the slash? 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...
ViciousXUSMC Posted June 21, 2016 Share Posted June 21, 2016 Because its a special character, unless Autoit is different. https://regex101.com/r/eQ5vG0/1 Link to comment Share on other sites More sharing options...
jchd Posted June 21, 2016 Share Posted June 21, 2016 / isn't a metacharacter in PCRE. Have you tried running the code? 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...
ViciousXUSMC Posted June 21, 2016 Share Posted June 21, 2016 No, that is why I prefaced "unless its different in AutoIt" I always use regex testers first since they are faster to test. Thanks for pointing it out however, now I know. Link to comment Share on other sites More sharing options...
jchd Posted June 21, 2016 Share Posted June 21, 2016 The slash is commonly used to delimit the pattern and options, but this is just an convenience for command-line apps which has made it thru history. AFAIK no regexp engine attaches a specific meaning to / within a pattern. Note that many command-line testers and apps consider the first non-alphanumeric character (and other exceptions) as pattern and option delimiter, say they work with /pattern/options/ as well as #pattern#options# 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...
HurleyShanabarger Posted June 21, 2016 Author Share Posted June 21, 2016 Thanks for all the replies. Isn't there an easier/other way? I am think about matching the word "This" and then stopping the match at the first occurence of "|" after that word. Link to comment Share on other sites More sharing options...
mikell Posted June 21, 2016 Share Posted June 21, 2016 (edited) An other way... The concept is : get the 6th content which is before a | on each line of text #include <Array.au3> #include <String.au3> Local $value = _ "|Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Want[0]|0|Decimal|6|9999.9|" & @CRLF & _ "|Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Want0|Decimal|6|9999.9|" & @CRLF & _ "|Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Wan|Decimal|6|9999.9|" & @CRLF Local $a = StringRegExp($Value, '(?m)^(?:.*?\|){5}([^\|]+)', 3) _ArrayDisplay($a) Edit"I am think about matching the word "This" and then stopping the match at the first occurence of "|" after that word." If you absolutely want to go this way then here it is, literally : Local $a = StringRegExp($Value, 'This[^\|]+', 3) Edited June 21, 2016 by mikell Link to comment Share on other sites More sharing options...
Malkey Posted June 21, 2016 Share Posted June 21, 2016 @StopHurleyShanabarg... To answer your question, use the lazy qualifier, "?", in your RE pattern. By default "*" is greedy and will match every character including all vertical bars, "|", to the very last vertical bar in the string to the right. #include <Array.au3> ; For display of array purposes only. Local $value = _ "|Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Want[0]|0|Decimal|6|9999.9|" & @CRLF & _ "|Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Want0|Decimal|6|9999.9|" & @CRLF & _ "|Property Window|PropertySheet: Utah.GraphX.PropertyView.IOField.General|Input/output|1 s|This.I.Wan|Decimal|6|9999.9|" & @CRLF Local $a = StringRegExp($value, "(This.*?)\|", 3) _ArrayDisplay($a) Link to comment Share on other sites More sharing options...
HurleyShanabarger Posted June 22, 2016 Author Share Posted June 22, 2016 Thank you for all the replies. Of course I failed to put in the request correctly in the first place, but all solution are of course providing the information I need. From the following solutions, is there one that is in someway better than the other ones? Local $a = StringRegExp($value, "(This.*?)(?=\|)", 3) Local $b = StringRegExp($value, "(This.*?)\|", 3) Local $c = StringRegExp($value, "This[^\|]+", 3) I am also wondering if it would be possible to integrate different beginnings into the pattern, so it would not only match something beginning with "This" but also with "That". Link to comment Share on other sites More sharing options...
mikell Posted June 22, 2016 Share Posted June 22, 2016 1 hour ago, HurleyShanabarger said: From the following solutions, is there one that is in someway better than the other ones? regex101 says : "(This.*?)(?=\|)" needs 105 steps to return the 3 matches "(This.*?)\|" needs 75 "(This[^\|]+)" needs 24 1 hour ago, HurleyShanabarger said: match something beginning with "This" but also with "That" Use an alternation in a non-capturing group Local $a = StringRegExp($Value, '(?:This|That)[^\|]+', 3) 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