Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Put here requests of problems with regular expressions


  • Please log in to reply
1074 replies to this topic
polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

Sorry, I don't understand. Do you mean RegExReplace(str, "e;", "", count)?

See my example a couple posts up.

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 :p

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

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? :roll:

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!

:)
kWo4Lk1.png

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I'm sure it's possible to avoid the extra chars with a conditional and an atomic grouped lookaround...


Please do not bash me! :D
kWo4Lk1.png

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
This will return count in my version:

v := RegExMatch(var, "e")
Posted Image

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

This will return count in my version:


What version? :roll:

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!
kWo4Lk1.png

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
You guessed wrong... I downloaded it from forum

Well...it seems that above doesn't work well...

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

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)
Posted Image

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear PhiLho, :)

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

:)
kWo4Lk1.png

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

Where do I get it? :roll:

Same address as the previous one: Regular Expressions (RegEx) for AutoHotkey

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...

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...

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:
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.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

counting a given word. No problem:

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! :D RegEx is very interesting!
kWo4Lk1.png

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

RegExReplace(str, "e;", "", count)?

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

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Goyyah (and Laszlo) prefer one-line solutions


Definitely yes!

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.

:)
kWo4Lk1.png

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006

Uh, no, in both versions, it returns the found position...

well, there is no documentation yet... :)


Thanks! RegEx is very interesting!

Yeah, goyyah, its perfect for your camp. :)
Posted Image

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

well, there is no documentation yet... :)

Only some lines in the first announce of the beta...
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Can a string be converted into Upper/Lower/Sentence case with RegExReplace?

Forgive me if it is a stupid request!
kWo4Lk1.png

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

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?

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit