Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Get rid of with regular expressions | Excel Discussion (Misc queries) | |||
Regular expressions in VB | Excel Discussion (Misc queries) | |||
Regular expressions in Excel? | Excel Programming | |||
Regular Expressions in VBA? | Excel Programming | |||
VBA and Regular expressions | Excel Programming |