rrhandle8
asked on
Regular expression to extract a string
I need to extract 1.50 in this string from the source code of the web page, or the entire line and then I'll parse it down to the 1.50.
<\/span>\n\n\n"},"MNN$":{" 9303565":" $1.50"},"W ARRANTY":{ }}),
I am using Excel VBA.
Here is the function
Sub ExtractData()
Dim regEx
Dim i As Long
Dim pattern As String
Set regEx = CreateObject("VBScript.Reg Exp")
regEx.IgnoreCase = True
regEx.Global = True
regEx.pattern = "[what do I put in here?]"
End Sub
<\/span>\n\n\n"},"MNN$":{"
I am using Excel VBA.
Here is the function
Sub ExtractData()
Dim regEx
Dim i As Long
Dim pattern As String
Set regEx = CreateObject("VBScript.Reg
regEx.IgnoreCase = True
regEx.Global = True
regEx.pattern = "[what do I put in here?]"
End Sub
include the quotes in the expression. You will need to double the quotes inside a string.
"$(\d+\.\d\d)"
ASKER
First I need to extract the entire line from the html document.
no, you don't
If you need just that one item, among many similar items, use this pattern
{"9303565":"$(\d+\.\d\d)"}
ASKER
OK. Thanks. I will try it.
ASKER
regEx.pattern = "{"9303565":"$(\d+\.\d\d)" }"
Expect end of statement error
Expect end of statement error
As I stated earlier, in order for a string literal to contain quote characters, the internal quote characters need to be doubled.
regEx.pattern = "{""9303565"":""$(\d+\.\d\d)""}"
ASKER
That didn't work either.
The 9303565 is a unique number, so I can understand why it does work on the items I an feeding.
The line would be like "MNN$":{"9303565":"$1.50"} where 9303565 changes, then the MNN$":{ is unique within the document.
The 9303565 is a unique number, so I can understand why it does work on the items I an feeding.
The line would be like "MNN$":{"9303565":"$1.50"}
That didn't work either.Are you still getting an error message?
What string are you using for your pattern matching? Are you sure it contains the 9303565 data?
I'm stepping away from the keyboard for a while.
ASKER
9303565 is a unique number that changes on each web page. I am looking for the $1.50 that is to the right of it.
the 1.50 will be in submatches(0)
If the number changes, then I should be able to alter the pattern to work in the general case if you tell me more about those values.
If the number changes, then I should be able to alter the pattern to work in the general case if you tell me more about those values.
ASKER
aikimark, Thanks for the help. I solved the problem using a different technique, but I would like to know how to do this with regular expressions.
There is only one line in the html that contains MNN$":{"9303565":"$1.50"}
The only thing that changes is the long number in the middle and the price.
There is always a long number in the middle, and a price at the end.
I have discovered that I need to extract long number in the middle and the price.
The regular expression should return (in this case) 9303565 and 1.50.
There is only one line in the html that contains MNN$":{"9303565":"$1.50"}
The only thing that changes is the long number in the middle and the price.
There is always a long number in the middle, and a price at the end.
I have discovered that I need to extract long number in the middle and the price.
The regular expression should return (in this case) 9303565 and 1.50.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
"MNN$":{"9303565":"$1.50"}