mikell Posted June 12, 2017 Share Posted June 12, 2017 tezhihi, Sorry. It was for a better readability indeed If you keep this pattern then of course all whitespaces can be removed - and the (?x) too I personally rarely use significant whitespaces in patterns, I better use \h etc which fit in most cases tezhihi 1 Link to comment Share on other sites More sharing options...
tezhihi Posted July 1, 2017 Author Share Posted July 1, 2017 (edited) Hi @mikell, Can i remove blank line in this file Example.txt with RegEx below: $e = StringRegExpReplace($e, "^(?:[\t ]*(?:\r?\n|\r))+", "") I try it can run successfully with notepad++. However when i try with autoit this script can not run . So please check the Results.txt and advise me Edited July 1, 2017 by tezhihi Link to comment Share on other sites More sharing options...
mikell Posted July 1, 2017 Share Posted July 1, 2017 Why a so complicated pattern ? Use this : - (?m) multiline option to make ^ match each start of line, - \s* for possible whitespaces, - \R for the ending newline sequence $r = StringRegExpReplace(FileRead("Example.txt"), '(?m)^\s*\R', "") FileWrite("result.txt", $r) tezhihi 1 Link to comment Share on other sites More sharing options...
tezhihi Posted July 21, 2017 Author Share Posted July 21, 2017 (edited) Hi @mikell Are I correct when use this script below for capture string 'D2596B055075' of path below. $a = 'H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075\aaaaaaaaaa\66666666666666\6666666666666666666666' ; or $a = 'H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075 $b = StringRegExpReplace($a, '(.*)\\(D.*?)(|\\(.*))', '$2') ConsoleWrite($b) Edited July 21, 2017 by tezhihi Link to comment Share on other sites More sharing options...
Trong Posted July 21, 2017 Share Posted July 21, 2017 9 minutes ago, tezhihi said: Hi @mikell Are I correct when use this script below for capture string 'D2596B055075' of path below. $a = 'H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075\aaaaaaaaaa\66666666666666\6666666666666666666666' ; or $a = 'H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075 $b = StringRegExpReplace($a, '(.*)\\(D.*?)(|\\(.*))', '$2') ConsoleWrite($b) use: _PathSplit() Regards, Link to comment Share on other sites More sharing options...
tezhihi Posted July 21, 2017 Author Share Posted July 21, 2017 (edited) 4 minutes ago, Trong said: use: _PathSplit() Just for dir ??????? u should run this script and understand what i mean. Edited July 21, 2017 by tezhihi Link to comment Share on other sites More sharing options...
Trong Posted July 21, 2017 Share Posted July 21, 2017 nop #include <Array.au3> #include <File.au3> Local $sFilePath='H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075' Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" Local $aPathSplit = _PathSplit($sFilePath, $sDrive, $sDir, $sFileName, $sExtension) _ArrayDisplay($aPathSplit, "_PathSplit of " & $sFilePath) Regards, Link to comment Share on other sites More sharing options...
tezhihi Posted July 21, 2017 Author Share Posted July 21, 2017 3 hours ago, Trong said: nop #include <Array.au3> #include <File.au3> Local $sFilePath='H:\01. PRODUCTION\01. NEW SHIPMENT\04-CASE RELATED AND NEWS AND BUSINESS\07-19-2017\Part C 16.00\D2596B055075' Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" Local $aPathSplit = _PathSplit($sFilePath, $sDrive, $sDir, $sFileName, $sExtension) _ArrayDisplay($aPathSplit, "_PathSplit of " & $sFilePath) I mean about catch only D2596B055075 not full file path @@. Find in string and replace and result is D2596B055075 Link to comment Share on other sites More sharing options...
Trong Posted July 21, 2017 Share Posted July 21, 2017 1 minute ago, tezhihi said: I mean about catch only D2596B055075 not full file path @@. Find in string and replace and result is D2596B055075 Whatever! Local $string = "Whatever! Something, somethinglt is D2596B055075 Whatever! Something, something" Local $searchstring = "D2596B055075" Local $replacestring = "Whatever!!!!!!!!!!!!!" Local $newString = StringReplace($string, $searchstring, $replacestring) ConsoleWrite($string & @CRLF) ConsoleWrite($newString & @CRLF) Regards, Link to comment Share on other sites More sharing options...
mikell Posted July 21, 2017 Share Posted July 21, 2017 (edited) @tezhihi The regex doesn't work because of the alternation in (|\\(.*)) : "match nothing or \\(.*)" . For the first string, (D.*?) returns everything after D If you remove the alternation it will work for the first but not for the second. And if you make the second part of the expression optional then it doesn't work for the first string again So assuming that the part you want always begins with a D, a correct way could be this $b = StringRegExpReplace($a, '.*\\(D[^\\]+).*', '$1') this expression matches "D and one or more non-backslash chars" (heeding the backslash just before the D) Edit Trong, sometimes you have to guess a little what is the real question and so what should be a correct answer i.e. the non-regex way Local $b, $split = StringSplit($a, "\") For $i = 2 to $split[0] If StringLeft($split[$i], 1) == "D" Then $b = $split[$i] Next msgbox(0,"", $b) Edited July 21, 2017 by mikell tezhihi 1 Link to comment Share on other sites More sharing options...
Trong Posted July 21, 2017 Share Posted July 21, 2017 27 minutes ago, mikell said: Trong, sometimes you have to guess a little what is the real question and so what should be a correct answer i.e. the non-regex way Local $b, $split = StringSplit($a, "\") For $i = 2 to $split[0] If StringLeft($split[$i], 1) == "D" Then $b = $split[$i] Next msgbox(0,"", $b) Sorry I have a problem communicating! And limited English proficiency, my friend is Google Translate. Regards, Link to comment Share on other sites More sharing options...
tezhihi Posted July 21, 2017 Author Share Posted July 21, 2017 3 minutes ago, Trong said: Sorry I have a problem communicating! And limited English proficiency, my friend is Google Translate. @Trong chung quy là ông ko hiểu tôi nói cái gì đúng không :)) @mikell thanks you so much. Link to comment Share on other sites More sharing options...
Trong Posted July 21, 2017 Share Posted July 21, 2017 Just now, tezhihi said: @Trong chung quy là ông ko hiểu tôi nói cái gì đúng không :)) đù Người Việt Tiếng Việt => English => Tiếng Việt thì khó hiểu bỏ mịa =]] Regards, Link to comment Share on other sites More sharing options...
tezhihi Posted July 21, 2017 Author Share Posted July 21, 2017 (edited) 1 minute ago, Trong said: đù Người Việt Tiếng Việt => English => Tiếng Việt thì khó hiểu bỏ mịa =]] Tôi thấy ông vào comment buồn cười quá nên cố tình thôi. Tôi đang hỏi về regex mà :)) đơn giản là tách cái D2506 xxx kia ra thôi chứ cái pathsplit hay string bla bla ko ra đâu tại đường dẫn nó thay đổi linh tinh. Ok cảm ơn nhé Edited July 21, 2017 by tezhihi Link to comment Share on other sites More sharing options...
Trong Posted July 21, 2017 Share Posted July 21, 2017 Những cái đó thì bạn phải nói rõ. Có cái gì, cần cái gì và muốn kết quả thế nào thì người ta mới dễ giúp chứ! Mà forum Việt nó không chào đón bạn à? Chỗ đó nó cấm tôi, cấm mọi nơi lên nơi đây là nhà của tôi! Regards, Link to comment Share on other sites More sharing options...
Developers Jos Posted July 21, 2017 Developers Share Posted July 21, 2017 (edited) Ok guys... back to English please in open forum. Just keep practicing it and you will soon master it. Jos Edited July 21, 2017 by Jos tezhihi and Trong 2 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
tezhihi Posted July 21, 2017 Author Share Posted July 21, 2017 1 hour ago, Jos said: Ok guys... back to English please in open forum. Just keep practicing it and you will soon master it. Jos This is noted. Thanks you Link to comment Share on other sites More sharing options...
tezhihi Posted October 28, 2017 Author Share Posted October 28, 2017 (edited) Hi @mikell, Long time no make a question :(. I need to get some data from manifest.xml as blue highlight of image show below. So please check and provide me the correctness of my regex below: Local $aLNI = StringRegExp($LNI, '.*guid="(.*?)"\soverrideConversionId.*', 1) Local $aSource = StringRegExp($LNI, '.*source" name="(.*?)" md5sum.*', 1) Local $Court = StringRegExp($LNI, '.*CLINV_code" value="(.*?)".*', 1) Local $CharCount = StringRegExp($LNI, '.*estKeyCharCount" value="(.*?)".*', 1) and if you can please provide me the way to use these regex in C#. Thanks you so much Edited October 28, 2017 by tezhihi Link to comment Share on other sites More sharing options...
mikell Posted October 28, 2017 Share Posted October 28, 2017 I'm not aware of C# constructs, but in AutoIt it could be like this #Include <Array.au3> $txt = FileRead("manifest.xml") $res = StringRegExp($txt, '(?|item id|guid|name|CLINV_code" value)="([^"]+)', 3) _ArrayDisplay($res) 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