Josbe Posted November 1, 2008 Share Posted November 1, 2008 (edited) Hi, I'm working in some code and I need extract some values with RegExp, my actual code is like this: $sLine = "somecharsOrSymbols===someCharsOrSymbols" $sRes= StringRegExp( $sLine, "(.*)===(.*)", 1) I would like excerpt two values between a tripple equal symbol (===), in most cases the code above works, but cases like "4 equals" not. E.g.: SomeTextWithOrNotSymbolsBefore===SomeTextWithOrNotSymbolsAfter Results what I need: $sRes[0] => "SomeTextWithOrNotSymbolsBefore" $sRes[1] => "SomeTextWithOrNotSymbolsAfter" RULES: NOT Allow: sometext====sometext sometext==sometext Allowed: sometext===some=text sometext===s=ome=text some==text===sometext some text with spaces===some text with symbols %,.== I would like an efficient pattern for the previous rules, because I'm not good with RegExp. Thxs. Edited November 1, 2008 by Josbe AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 1, 2008 Moderators Share Posted November 1, 2008 (edited) $s_val_1 = "Or" $s_val_2 = "Not" $s_line = "somecharsOrSymbols===someCharsOrSymbols" $s_res = StringRegExpReplace($s_line, "(.*?)(\b={3}\b)(.*?)", "\1" & $s_val_1 & $s_val_2 & "\3") ConsoleWrite($s_res & @CRLF) Edited November 1, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Josbe Posted November 1, 2008 Author Share Posted November 1, 2008 $s_val_1 = "Or" $s_val_2 = "Not" $s_line = "somecharsOrSymbols===someCharsOrSymbols" $s_res = StringRegExpReplace($s_line, "(.*?)(\b={3}\b)(.*?)", "\1" & $s_val_1 & $s_val_2 & "\3") ConsoleWrite($s_res & @CRLF)oÝ÷ Ûú®¢×êÞ¦Vx"·l¶§Æî¶f²mâ7öl+¢x"Ëaz·,ÊÚÆÚÚrÛazö¥¹ë.²)àEèÆÛ «¬zlzËlºÈ§*.®µêçÁ«ºÚ"µÍÚ[ÛYH Ð^K]LÉÝÂÌÍÜ×Û[HH ][ÝÐÛÛÜOOTY ][ÝÂÌÍÜ×ÜÈHÝ[ÔYÑ^ ÌÍÜ×Û[K ][ÝÊÊJ ÌLØ^ÌßIÌLØJÊI][ÝËJBÐ^QÜ^J ÌÍÜ×ÜË ][ÝÝÝ[É][ÝÊ Output: I would like this: Output: *I'm using the flag 1 to return an array. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 1, 2008 Moderators Share Posted November 1, 2008 $s_line = "somecharsOrSymbols===someCharsOrSymbols" $a_res = StringRegExp($s_line, "(.*?)\b={3}\b(.*?)\z", 1) _ArrayDisplay($a_res) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
rasim Posted November 1, 2008 Share Posted November 1, 2008 My 5 cents: #include <Array.au3> $s_line = "somecharsOrSymbols===someCharsOrSymbols" $a_res = StringRegExp($s_line, "(.*?)=+(.*)", 1) _ArrayDisplay($a_res) Link to comment Share on other sites More sharing options...
trancexx Posted November 1, 2008 Share Posted November 1, 2008 My 5 cents: #include <Array.au3> $s_line = "somecharsOrSymbols===someCharsOrSymbols" $a_res = StringRegExp($s_line, "(.*?)=+(.*)", 1) _ArrayDisplay($a_res) Not 1,2,4,5,6,7... but only 3 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
rasim Posted November 1, 2008 Share Posted November 1, 2008 Not 1,2,4,5,6,7... but only 3 My miss, sorry Link to comment Share on other sites More sharing options...
Josbe Posted November 1, 2008 Author Share Posted November 1, 2008 $s_line = "somecharsOrSymbols===someCharsOrSymbols" $a_res = StringRegExp($s_line, "(.*?)\b={3}\b(.*?)\z", 1) _ArrayDisplay($a_res)@SmOke_N: Great. Thanks. @rasim: Don't worry, thanks for trying. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
TerarinK Posted February 7, 2009 Share Posted February 7, 2009 (edited) You know Smoke_N that is a good example but that got me to thinking about how we are doing these. Look at the example I'm going to give you: "Random Text somecharsOrSymbols===someCharsOrSymbols Random Text" "Random Text somecharsOrSymbols===someCharsOrSymbols" "somecharsOrSymbols===someCharsOrSymbols Random Text" "somecharsOrSymbols===someCharsOrSymbols" With these four examples can you accomplish this task all in a single command line? I also added a . after the word and before therefore adding another twelve more to the list therefore ending with sixteen total. Now knowing that I can't go off the "Random Text" because well it is random I lookup the pcrepattern specification and found the lookbehind assertions, but I found out that you can't use backwards compution on a unknown value. So back to the board I go, after thinking about this I came up with a character solution. $aResult = StringRegExp($sValue, "(?:\B)(\w*?)\b={3}\b(\w*?)(?:\W|\z)", 1) This script copies the first word and checks the second word if it is a a-zAZ or "_" is it is true then finds three characters of = then searches again for the word a-zA-Z or "_". Now I finally get to the part the stumps me using the \W, as not in finding a-zA-Z or "_" but any other character. I could use a "." but then what about the other end caps? Now I could put .|?|!|,|'|"|:|;|[|{|]|} covering all the possible outcomes but then wouldn't I need to do the same for the character and symbols put down every symbol I know of? Edited February 7, 2009 by TerarinK 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E Link to comment Share on other sites More sharing options...
TerarinK Posted February 8, 2009 Share Posted February 8, 2009 I got it btw #include <array.au3> $sValue = "Hello, my name is test. text text .somecharsO$rSymbols===someCh$arsOr_Symbols. text" $aResult = StringRegExp($sValue, "(?:\B)([a-zA-Z#-&_@]*?)\b={3}\b([a-zA-Z#-&_@]*?)(?:(?:[!""'-),.:;?]|\s)|\z)", 1) _ArrayDisplay($aResult)oÝ÷ Ù8^ì²z-~éܶ*'²æyÙ²£ ì¢+r¢ìÛhr·µë(çîËb¢wè®)íêÞ¶§Ê§yçm¡×ªÞ¶¦¢{h¥©Ýë-¦VzØ^uç%j¶âØ^~éܶ*')¶¬jëh×6#include <array.au3> $sCharSymbol = "([a-zA-Z#-&_@]*?)" $sEndStatement = "[!""'-),.:;?]" $sValue = "Hello, my name is test. text text .somecharsO$rSymbols===someCh$arsOr_Symbols. text" $aResult = StringRegExp($sValue, "(?:\B)" & $sCharSymbol & "\b={3}\b" & $sCharSymbol & "(?:(?:" & $sEndStatement & "|\s)|\z)", 1) _ArrayDisplay($aResult) 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E 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