Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Regular expressions

I've been working with some html and am trying to use regular
expressions to get a value. Here is what I'm looking for
"handStatus[0] = '(I need this data)';"

I need to find the part that says I need this data, the () are not part
of the string but the ' are. This is what I've tried, but I've never
really worked with Regexp, could somebody tell me what I need to fix?

Set RegEx = New RegExp
anyStr = myIE.document.body.innerText
RegEx.Pattern = "handStatus[0] = '(\w)';"
RegEx.IgnoreCase = True
RegEx.Global = True ' Set global applicability.
Set match = RegEx.Execute(anyStr) ' Execute search.
MsgBox (match.Value)

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Regular expressions

Here's one way. There may be a better way to test for a character other
than \D\d, but I don't know it off hand. Maybe someone can jump in with a
better test.

Sub TestIt()
Debug.Print GetString("handStatus[0] = 'I need this data' ")
End Sub

Function GetString(s As String)
Dim re
Set re = New RegExp

re.IgnoreCase = True
re.Global = True
re.MultiLine = True
re.Pattern = "'([\D|\d]+)'"

If re.test(s) Then
GetString = re.Execute(s)(0).SubMatches(0)
End If
End Function

--
HTH. :)
Dana DeLouis
Windows XP, Office 2003


"JeffMelton" wrote in message
oups.com...
I've been working with some html and am trying to use regular
expressions to get a value. Here is what I'm looking for
"handStatus[0] = '(I need this data)';"

I need to find the part that says I need this data, the () are not part
of the string but the ' are. This is what I've tried, but I've never
really worked with Regexp, could somebody tell me what I need to fix?

Set RegEx = New RegExp
anyStr = myIE.document.body.innerText
RegEx.Pattern = "handStatus[0] = '(\w)';"
RegEx.IgnoreCase = True
RegEx.Global = True ' Set global applicability.
Set match = RegEx.Execute(anyStr) ' Execute search.
MsgBox (match.Value)

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Regular expressions

"Dana DeLouis" wrote in message
...
: Here's one way. There may be a better way to test for a character other
: than \D\d, but I don't know it off hand. Maybe someone can jump in with a
: better test.
:
: Sub TestIt()
: Debug.Print GetString("handStatus[0] = 'I need this data' ")
: End Sub
:
: Function GetString(s As String)
: Dim re
: Set re = New RegExp
:
: re.IgnoreCase = True
: re.Global = True
: re.MultiLine = True
: re.Pattern = "'([\D|\d]+)'"
:
: If re.test(s) Then
: GetString = re.Execute(s)(0).SubMatches(0)
: End If
: End Function
:
: --
: HTH. :)
: Dana DeLouis
: Windows XP, Office 2003

Considering this is HTML, what if there is an entry that has "FootStatus[0]
= ... or "handStatus[1]=...
To only search for what was stated try this

Public Sub NeedData()
Dim anyStr As String
Dim regx As RegExp
Dim match As MatchCollection

Set regx = New RegExp
anyStr = myIE.document.body.innerText
regx.Pattern = "(handStatus\[0\] = ')([\w|\s]+)'"
regx.IgnoreCase = True
regx.Global = True ' Set global applicability.
Set match = regx.Execute(anyStr) ' Execute search.
If match.Count 0 Then
MsgBox match(0).SubMatches(1)
End If
Set regx = Nothing
Set match = Nothing
End Sub

This routine only returns the first match of this string 'match(0)', if it
is possible to have more than one match, you should iterate through the
matchcollection to get all the values.
Paul D


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get rid of with regular expressions Howdy Excel Discussion (Misc queries) 1 January 18th 10 07:42 PM
Regular expressions in VB FiluDlidu Excel Discussion (Misc queries) 4 March 21st 08 01:10 AM
Regular expressions in Excel? a Excel Programming 8 March 4th 05 05:29 AM
Regular Expressions in VBA? Rob[_23_] Excel Programming 13 February 10th 05 05:34 AM
VBA and Regular expressions Friedrich Muecke Excel Programming 3 October 3rd 03 01:46 AM


All times are GMT +1. The time now is 04:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"