 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Titan
Joined: 11 Aug 2004 Posts: 5376 Location: /b/
|
Posted: Tue Oct 24, 2006 2:05 pm Post subject: |
|
|
| PhiLho wrote: | | Sorry, I don't understand. Do you mean RegExReplace(str, "e;", "", count)? | See my example a couple posts up.
| Goyyah wrote: | | Oh! I did not guess that would be tough. | I'm no regex expert. I'm sure it's possible to avoid the extra chars with a conditional and an atomic grouped lookaround... but I'll leave that to PhiLho, majkinetor, JSLover and the other regex nerds  _________________
 |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Tue Oct 24, 2006 2:07 pm Post subject: |
|
|
| PhiLho wrote: | | 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. |
Where do I get it?
| PhiLho wrote: | | Sorry, I don't understand. Do you mean RegExReplace(str, "e;", "", count)? |
I want to count e; in "One;Two;Three;Four;Five",
the result will be 2!
 _________________
 |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Tue Oct 24, 2006 2:09 pm Post subject: |
|
|
| Titan wrote: | | I'm sure it's possible to avoid the extra chars with a conditional and an atomic grouped lookaround... |
Please do not bash me!  _________________
 |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3644 Location: Belgrade
|
Posted: Tue Oct 24, 2006 2:12 pm Post subject: |
|
|
This will return count in my version:
v := RegExMatch(var, "e") _________________
 |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Tue Oct 24, 2006 2:15 pm Post subject: |
|
|
| majkinetor wrote: | | This will return count in my version: |
What version?
Let me guess.. you guys were privately notified with a link for download?
Edit: Stupid of me! I do not know how I missed it! _________________

Last edited by SKAN on Tue Oct 24, 2006 2:44 pm; edited 1 time in total |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3644 Location: Belgrade
|
Posted: Tue Oct 24, 2006 2:17 pm Post subject: |
|
|
You guessed wrong... I downloaded it from forum
Well...it seems that above doesn't work well...
| Code: | var := "mone;y toke;ne"
v := RegExMatch(var, "e;")
msgbox %v% |
Returns 4
RegExMatch (var, "o") returns 2
RegExMatch(var, "e;y") returns 4 ...
RegExMatch(var, "`;y") returns 5 ?
I don't get this really as
| Quote: |
var := "mone;y toke;ne"
v := RegExReplace(var, "e;", "", count)
msgbox %count% |
Returns 2
For now, goyah, you can use RegExReplace(var, "e;", "e;", count) _________________
 |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Tue Oct 24, 2006 2:51 pm Post subject: |
|
|
Dear PhiLho,
| Code: | str = Recommended for new scripts due to its superior speed and reliability.
RegExReplace(str, "\w+", "", count)
MsgBox % count |
Thats cool too.. but I meant searching a whole word.. For example:
"The Theft Broke-in Through The Window"
I want to search for "the" ( case insensitive ) and result should be 2 .. not 3
 _________________
 |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Oct 24, 2006 3:07 pm Post subject: |
|
|
| Goyyah wrote: | Where do I get it?  | Same address as the previous one: Regular Expressions (RegEx) for AutoHotkey
| Goyyah wrote: | I want to count e; in "One;Two;Three;Four;Five",
the result will be 2! | Yes, that's what I gave (again, lastest version!). I was lost because Titan provided a complex expression...
| majkinetor wrote: | This will return count in my version:
v := RegExMatch(var, "e")
[...]
Well...it seems that above doesn't work well... | Uh, no, in both versions, it returns the found position...
| Goyyah wrote: | Thats cool too.. but I meant searching a whole word.. For example:
"The Theft Broke-in Through The Window"
I want to search for "the" ( case insensitive ) and result should be 2 .. not 3 | Ah, counting a given word. No problem:
| Code: | str = The Theft Broke-in Through The Window
RegExReplace(str, "i)\bthe\b", "", count)
msgbox %count% | \b is "word bound", working also on string ends. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Tue Oct 24, 2006 3:24 pm Post subject: |
|
|
| PhiLho wrote: | counting a given word. No problem:
| Code: | str = The Theft Broke-in Through The Window
RegExReplace(str, "i)\bthe\b", "", count)
msgbox %count% | \b is "word bound", working also on string ends. |
Thanks! RegEx is very interesting! _________________
 |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5376 Location: /b/
|
Posted: Tue Oct 24, 2006 3:29 pm Post subject: |
|
|
| PhiLho wrote: | | RegExReplace(str, "e;", "", count)? |
| PhiLho wrote: | | I was lost because Titan provided a complex expression... |
Oh I never knew RegExReplace had that feature. I also didn't know how to convert ++/e;/.exec('one; two; three; four').length; javascript to ahk, hence my long-winded approach. Goyyah (and Laszlo) prefer one-line solutions so: Asc(RegExReplace("one; two; three; four", "e;", "", c)) * 0 + c _________________
 |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Tue Oct 24, 2006 3:36 pm Post subject: |
|
|
| Titan wrote: | | Goyyah (and Laszlo) prefer one-line solutions |
Definitely yes!
| Code: | str = The Theft Broke-in Through The Window of The House
MsgBox, % Asc(RegExReplace(str,"i)\bthe\b", "", count)) * 0 + count |
Many thanks for coming up with that technique! Readable or not, if it is going to be inside my function, I prefer one-liners.
 _________________
 |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3644 Location: Belgrade
|
Posted: Tue Oct 24, 2006 4:10 pm Post subject: |
|
|
| Quote: | | Uh, no, in both versions, it returns the found position... |
well, there is no documentation yet...
| Quote: | | Thanks! RegEx is very interesting! |
Yeah, goyyah, its perfect for your camp.  _________________
 |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Oct 24, 2006 4:30 pm Post subject: |
|
|
| majkinetor wrote: | well, there is no documentation yet...  | Only some lines in the first announce of the beta... _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Tue Oct 24, 2006 4:41 pm Post subject: |
|
|
Can a string be converted into Upper/Lower/Sentence case with RegExReplace?
Forgive me if it is a stupid request! _________________
 |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5376 Location: /b/
|
Posted: Tue Oct 24, 2006 4:58 pm Post subject: |
|
|
| Goyyah wrote: | | Can a string be converted into Upper/Lower/Sentence case with RegExReplace? | I don't think it's possible, what's wrong with StringLower/StringUpper anyway? _________________
 |
|
| 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
|