 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Mon Oct 23, 2006 11:27 pm Post subject: |
|
|
Should include in the test:
| Code: | Loop C:\*.BMP,0,1
{
imageFiles := imageFiles . A_LoopFileLongPath . "`n"
}
Loop C:\*.JPG,0,1
{
imageFiles := imageFiles . A_LoopFileLongPath . "`n"
}
Loop C:\*.GIF,0,1
{
imageFiles := imageFiles . A_LoopFileLongPath . "`n"
}
| Probably faster, as the system returns only relevant files, instead of getting all files and filtering them after. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Tue Oct 24, 2006 6:44 am Post subject: |
|
|
My test was RegExMatch Vs SplitPath ..  _________________
 |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Tue Oct 24, 2006 9:50 am Post subject: |
|
|
Yeah, I was thinking about PhiLhos test.
| Quote: | | Probably faster, as the system returns only relevant files, instead of getting all files and filtering them after. |
Probably faster ?  _________________
 |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5128 Location: eth0 ::1
|
Posted: Tue Oct 24, 2006 11:37 am Post subject: |
|
|
| Goyyah wrote: | My test was RegExMatch Vs SplitPath ..  |
This test is based upon if..in and regex: | Code: | SetBatchLines, -1
Process, Priority, , R
dir = %A_MyDocuments%\*.*
i = 100
t1 := A_TickCount
Loop, %i% {
Loop, %dir%, , 1
If A_LoopFileExt in bmp,jpg,gif
list = %list%%A_LoopFileFullPath%`n
list := ""
}
t2 := A_TickCount
Loop, %i% {
Loop, %dir%, , 1
If RegExMatch(A_LoopFileExt, "^bmp|jpg|gif$", "i")
list = %list%%A_LoopFileFullPath%`n
list := ""
}
t3 := A_TickCount
MsgBox, % "if..in:`t" . t2 - t1 . "`nregex:`t" . t3 - t2 |
Seems like regex is faster!!1 _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Tue Oct 24, 2006 11:49 am Post subject: |
|
|
@Titan: Unbelievable! I never knew A_LoopFileExt existed!  _________________

Last edited by SKAN on Tue Oct 24, 2006 11:49 am; edited 1 time in total |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Tue Oct 24, 2006 11:49 am Post subject: |
|
|
Look like we got superb tool to play with.
I can not get it how RegExp can be faster than any concrete string function, but this just proves that this re implementation is good and optmised. _________________
 |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5128 Location: eth0 ::1
|
Posted: Tue Oct 24, 2006 11:52 am Post subject: |
|
|
| majkinetor wrote: | | this just proves that this re implementation is good and optmised. | What is it btw, pcre 6.7? _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Tue Oct 24, 2006 12:07 pm Post subject: |
|
|
How to find the number of a particular character/string/whole word present in a string?
My basic need is find the number of delimiters in a string and would like to have a one line solution like:
| Code: | ;I want to ascertain the number of semi colons and add 1 to
; find the no.of fields
FieldCount := RegEx??("Apples;Bananas;Cherries", ...) + 1 |
Refer this post: http://www.autohotkey.com/forum/viewtopic.php?p=84194#84194
I would also like to know how the matches can be counted for a substring or a whole word
Please refer this topic : Count instances of a word appears in a file
 _________________
 |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5128 Location: eth0 ::1
|
Posted: Tue Oct 24, 2006 12:37 pm Post subject: |
|
|
| Goyyah wrote: | | How to find the number of a particular character/string/whole word present in a string? | Easy: MsgBox, % StrLen(RegExReplace("one; two; three; four", "[^;]", "")) _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Oct 24, 2006 12:48 pm Post subject: |
|
|
| Titan wrote: | | majkinetor wrote: | | this just proves that this re implementation is good and optmised. | What is it btw, pcre 6.7? | I believe so.
Indeed, the code is highly optimized. For example, author doesn't hesitate to put similar code several time to avoid adding a test in the loop... And it uses goto when it saves some CPU cycles!
I didn't saw that in PCRE code (but might have skipped it), but some implementations can detect that the RE is plain text. In this case, they just use an optimized Boyer-Moore string search...
Goyyah, I made a variant of the SplitPath functions, published in the other topic. They might not please you, as they don't use simple assignment, but I felt I had to test this possibility.
It seems latest beta (options in regex) broke the multiline (extended) REs, I will report that.
To answer your latest request is easy, Chris provided a OutputVarCount to the RegExReplace function:
| Code: | str = Apples;Bananas;Cherries
RegExReplace(str, ";", "", count)
FieldCount := count + 1
MsgBox % FieldCount
str = Recommended for new scripts due to its superior speed and reliability.
RegExReplace(str, "\w+", "", count)
MsgBox % count
|
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Tue Oct 24, 2006 1:07 pm Post subject: |
|
|
| PhiLho wrote: | | Goyyah, I made a variant of the SplitPath functions, published in the other topic. |
Thanks for the elaborate posting!
BTW, R: How to emulate StringSplit? should be R: How to emulate SplitPath?, I guess!
I am posting here because I do not want to mess that topic.
I would like to see that topic become sticky someday!
| Quote: | | To answer your latest request is easy, Chris provided a OutputVarCount to the RegExReplace function |
I get blank values!
 _________________
 |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Tue Oct 24, 2006 1:12 pm Post subject: |
|
|
| Titan wrote: | | MsgBox, % StrLen(RegExReplace("one; two; three; four", "[^;]", "")) |
Works fine! Thanks!
How do I count "e;" from that string?
 _________________
 |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5128 Location: eth0 ::1
|
Posted: Tue Oct 24, 2006 2:51 pm Post subject: |
|
|
| Goyyah wrote: | | How do I count "e;" from that string? | That's quite tricky - it's like doing a StringReplace (All). One way is to: StrLen(RegExReplace("one; two; three; four" . " ", ".*?(?:(?<=e;)(.)|$)", "$1")) but it requires at least one character at the end of the string to catch ending delimiters. _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6084
|
Posted: Tue Oct 24, 2006 2:57 pm Post subject: |
|
|
| Titan wrote: | | it requires at least one character at the end of the string to catch ending delimiters. |
Oh! I did not guess that would be tough. Many thanks!  _________________
 |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Oct 24, 2006 2:59 pm Post subject: |
|
|
| Goyyah wrote: | I get blank values! | I tested the above with the latest beta, did you got it? I can't remember if this count of replaces was in the previous version.
| Goyyah wrote: | | How do I count "e;" from that string? | Sorry, I don't understand. Do you mean RegExReplace(str, "e;", "", count)? _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|