peispud
asked on
Regex Find word within string
Hi. I am having some trouble to get the pattern for the following
Match criteria
1) word begins with 4 alphabetical characters
2) immediately followed by "PE"
3) get the rest of the word
string to be searched = "This is the sample string abcdPEy2c4s where I hope to get that weird word."
I would like the result to be abcdPEy2c4s
ps.. The string may be multiline.
Thank you.
Match criteria
1) word begins with 4 alphabetical characters
2) immediately followed by "PE"
3) get the rest of the word
string to be searched = "This is the sample string abcdPEy2c4s where I hope to get that weird word."
I would like the result to be abcdPEy2c4s
ps.. The string may be multiline.
Thank you.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Also, I should mention that I am using VBA in Microsoft Access.
ASKER
Correction
The code segment that I sent earlier was in error.
The code segment that I sent earlier was in error.
Dim str As String
str = "smsdpe01k01"
Dim reg As New regExp
reg.pattern = "(?<=[a-zA-Z]{4}PE).*$"
reg.Global = True
reg.IgnoreCase = True
Dim Matches As MatchCollection
Set Matches = reg.Execute(str)
Dim theanswer As String
theanswer = Matches.Item(0)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all.
Bill Prew and Subodh Tiwari's reply were perfect. I also appreciate IT_Saige's answer.
Bill Prew and Subodh Tiwari's reply were perfect. I also appreciate IT_Saige's answer.
You're welcome Peispud! Glad it worked as desired.
:) :) ;)
ASKER
I tried it, but came up with error "method 'multi line' of object 'regexp 2' failed"
Here is the complete code. Any ideas?
Open in new window