Solved Regular Expression to detect end of word (1 Viewer)

Dreamweaver

Well-known member
Local time
Today, 07:58
Joined
Nov 28, 2005
Messages
2,466
Hi crystal.
As you know I played with this but had to give up as my method just didn't work

I was looking at the statements like If, Dim which I think always starts a line.

There are other constants in the public sub, private sub, public function, private function, end sub, end function

Good luck mick
 

strive4peace

AWF VIP
Local time
Today, 01:58
Joined
Apr 3, 2020
Messages
1,002
thanks, theDBguy, haven't tried anything yet! (doing chores). It looks promising though. Is that running the code on your web page, just using a different pattern?

thanks too, James - Welcome to Access World forums :)
 
Last edited:

strive4peace

AWF VIP
Local time
Today, 01:58
Joined
Apr 3, 2020
Messages
1,002
Hi crystal.
As you know I played with this but had to give up as my method just didn't work
I was looking at the statements like If, Dim which I think always starts a line.
There are other constants in the public sub, private sub, public function, private function, end sub, end function
Good luck mick

thanks! YOU are the reason I'm digging into this now ... too embarrassing to share the code I've been using to do it ;)
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:58
Joined
Oct 29, 2018
Messages
21,536
thanks, theDBguy, haven't tried anything yet! (doing chores). It looks promising though. Is that running the code on your web page, just using a different pattern?

thanks too, James - Welcome to Access World forums :)
@strive4peace that's correct. I used the ExtractEmailAddress() function from the website but used the pattern "\b\w+\b" for the above test.
 

strive4peace

AWF VIP
Local time
Today, 01:58
Joined
Apr 3, 2020
Messages
1,002
thanks for all the ideas, everyone! Now I'm off to see how to make it run fast with good performance ... oh stopwatch where are you? ;)
 

strive4peace

AWF VIP
Local time
Today, 01:58
Joined
Apr 3, 2020
Messages
1,002
I am no expert, but I would say definitely yes. I assume you need a pattern of only letters ending in a non letter character excluding numbers. I would pm @arnelgp . He seems to be the guru on regexp. I would have to play with it too long. There are some great resources on line where you can test your pattern.
thanks, Maj, I did. You have some great posts here -- I've marked some to study, such as what you've shared about treeviews and classes, which are always on my back-burner ;)

Now that I see how to get the words with Regular Expressions (thanks theDBguy especially, I would love to know ... perhaps there is a way to return the entire substring that was tested? with the outside text that wasn't counted in the word? ... and can I specify a replacement phrase in the regular expression? Small words like IN are everywhere!

If not, I guess an alternative is to loop through the original string, as RegExp finds them, and store more information. That would need to run in theDBguy's loop: For Each var In regExMatch

thank you for any insight you can share ... I want to understand whats happening too. I've gotten help with regular expressions before, but it just hasn't sunk in yet ... waiting for that light bulb to come on💡
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:58
Joined
Oct 29, 2018
Messages
21,536
thanks, Maj, I did. You have some great posts here -- I've marked some to study, such as what you've shared about treeviews and classes, which are always on my back-burner ;)

Now that I see how to get the words with Regular Expressions (thanks theDBguy especially, I would love to know ... perhaps there is a way to return the entire substring that was tested? with the outside text that wasn't counted in the word? ... and can I specify a replacement phrase in the regular expression? Small words like IN are everywhere!

If not, I guess an alternative is to loop through the original string, as RegExp finds them, and store more information. That would need to run in theDBguy's loop: For Each var In regExMatch

thank you for any insight you can share ... I want to understand whats happening too. I've gotten help with regular expressions before, but it just hasn't sunk in yet ... waiting for that light bulb to come on💡
Hi @strive4peace. Check out this previous post at UA where I replaced the pattern found using regex. Hope that helps...
 

strive4peace

AWF VIP
Local time
Today, 01:58
Joined
Apr 3, 2020
Messages
1,002
thanks, theDBguy. btw, link is bad in "the code I had from here"

the problem with that code is that replace isn't position-dependent ... need to know where the word IS (can't just going replacing every occurrence of IN, for instance) ... hence knowing more than the word found by regExMatch would be helpful -- like the delimiters around it too. Would be nice to explore the object model, provided it can be found!
 

deletedT

Guest
Local time
Today, 07:58
Joined
Feb 2, 2019
Messages
1,218
I think everybody already knows it, but when it comes to Regex, I love this site because it gives a live result. Specially a mouse over each part in Explain tab every section's role is shown.

 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:58
Joined
Oct 29, 2018
Messages
21,536
thanks, theDBguy. btw, link is bad in "the code I had from here"

the problem with that code is that replace isn't position-dependent ... need to know where the word IS (can't just going replacing every occurrence of IN, for instance) ... hence knowing more than the word found by regExMatch would be helpful -- like the delimiters around it too. Would be nice to explore the object model, provided it can be found!
Hi @strive4peace. Thanks for the info on the bad link. It's now fixed. That was because the website got moved to a new host. Cheers!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:58
Joined
May 7, 2009
Messages
19,246
on your post #1, are those separate words?
what results do you expect?
from the first word down, you will get this when used on this function.
,
)
)
,
Code:
Public Function udfTerminatorChar(ByVal p As Variant) As Variant
    Const sPattern As String = "(.)*"
    If Trim(p & "") = "" Then Exit Function
    With CreateObject("VBScript.RegExp")
        .Global = True
        .IgnoreCase = True
        .Pattern = sPattern
        'Debug.Print .test(p)
        p = .Replace(p, "$1")
    End With
    While InStr(p, "  ")
        p = Replace(p, "  ", " ")
    Wend
    udfTerminatorChar = p
End Function
 

strive4peace

AWF VIP
Local time
Today, 01:58
Joined
Apr 3, 2020
Messages
1,002
on your post #1, are those separate words? YES
what results do you expect? To know what the words are, and what character(s) are around them
...

thanks, Arne. Would you please explain this:
p = .Replace(p, "$1")

I see you also replace 2 spaces with 1 -- to correct changes made to get the logic to work better? ... I'm imagining since my first solution was to add space around other delimiter characters before Split into array by space -- and maybe that isn't so kludgey after all?

thank you!!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:58
Joined
May 7, 2009
Messages
19,246
it refers to the first "group" (the expression inside the parenthesis on sPattern).
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 02:58
Joined
Apr 27, 2015
Messages
6,394
I downloaded this book a while back in a vain attempt to master regex...and the quest continues. I've attached it in case anyone else wants to embark on this journey.

The file is too large to attach - even zipped. If you are interested, send me a PM with your e-mail and I'll send it on.
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:58
Joined
Sep 21, 2011
Messages
14,442
John,
I'll take a copy please.
 

Users who are viewing this thread

Top Bottom