AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Put here requests of problems with regular expressions
Goto page Previous  1, 2, 3, 4 ... 17, 18, 19  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Mon Oct 23, 2006 11:27 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Tue Oct 24, 2006 6:44 am    Post subject: Reply with quote

My test was RegExMatch Vs SplitPath .. Smile
_________________
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Tue Oct 24, 2006 9:50 am    Post subject: Reply with quote

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 ? Very Happy
_________________
Back to top
View user's profile Send private message MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5128
Location: eth0 ::1

PostPosted: Tue Oct 24, 2006 11:37 am    Post subject: Reply with quote

Goyyah wrote:
My test was RegExMatch Vs SplitPath .. Smile

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Tue Oct 24, 2006 11:49 am    Post subject: Reply with quote

@Titan: Unbelievable! Shocked I never knew A_LoopFileExt existed! Sad
_________________


Last edited by SKAN on Tue Oct 24, 2006 11:49 am; edited 1 time in total
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Tue Oct 24, 2006 11:49 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5128
Location: eth0 ::1

PostPosted: Tue Oct 24, 2006 11:52 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Tue Oct 24, 2006 12:07 pm    Post subject: Reply with quote

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

Question
_________________
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5128
Location: eth0 ::1

PostPosted: Tue Oct 24, 2006 12:37 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Tue Oct 24, 2006 12:48 pm    Post subject: Reply with quote

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! Smile
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
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Tue Oct 24, 2006 1:07 pm    Post subject: Reply with quote

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! Smile

Quote:
To answer your latest request is easy, Chris provided a OutputVarCount to the RegExReplace function


I get blank values! Rolling Eyes

Smile
_________________
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Tue Oct 24, 2006 1:12 pm    Post subject: Reply with quote

Titan wrote:
MsgBox, % StrLen(RegExReplace("one; two; three; four", "[^;]", ""))


Works fine! Thanks!
How do I count "e;" from that string?

Smile
_________________
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5128
Location: eth0 ::1

PostPosted: Tue Oct 24, 2006 2:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
SKAN



Joined: 26 Dec 2005
Posts: 6084

PostPosted: Tue Oct 24, 2006 2:57 pm    Post subject: Reply with quote

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! Very Happy
_________________
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Tue Oct 24, 2006 2:59 pm    Post subject: Reply with quote

Goyyah wrote:
I get blank values! Rolling Eyes
Question 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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2, 3, 4 ... 17, 18, 19  Next
Page 3 of 19

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group