By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,659 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,659 IT Pros & Developers. It's quick & easy.

RegEx.. Finding pattern?

P: 80
Hi All!
I'm a little confused by using RegExe in general.
Does anybody know how the pattern would look like if I needed to print out anything in between two known blocks?

The code looks like this:
Expand|Select|Wrap|Line Numbers
  1. <span class=bld>2832.1600 USD</span>
I would need to extract the number 2832.1600

Thanks!
Frederik
Feb 19 '11 #1

✓ answered by Monomachus

Well in general for testing I'd recommend Rubular.com or a Regex Testing tool from Rad Software http://www.radsoftware.com.au/regexdesigner/

extract the number which can be done in many way depending on what exactly you are trying to parse.

See Rubular link for your particular example
http://www.rubular.com/r/GeJRrZS7E1

The pattern is
^<span.*?>(\d*\.\d*).*<\/span>$

Now the explanation
From the start of the line (^ character)
You need to have "<span" characters
Followed by some other characters until the ">" character (it is done by using .*? non greedy technique which takes character after character (?) and sees if it matches)
Now you'll have 0 or more digits followed by a point and than followed by 0 or more digits (\d*\.\d* - it is also saved with the parenthesis)
Followed by 0 or more characters (.*)
Until "</span>" characters
And the line should end here ($ character)

Share this Question
Share on Google+
4 Replies


Monomachus
Expert 100+
P: 127
Well in general for testing I'd recommend Rubular.com or a Regex Testing tool from Rad Software http://www.radsoftware.com.au/regexdesigner/

extract the number which can be done in many way depending on what exactly you are trying to parse.

See Rubular link for your particular example
http://www.rubular.com/r/GeJRrZS7E1

The pattern is
^<span.*?>(\d*\.\d*).*<\/span>$

Now the explanation
From the start of the line (^ character)
You need to have "<span" characters
Followed by some other characters until the ">" character (it is done by using .*? non greedy technique which takes character after character (?) and sees if it matches)
Now you'll have 0 or more digits followed by a point and than followed by 0 or more digits (\d*\.\d* - it is also saved with the parenthesis)
Followed by 0 or more characters (.*)
Until "</span>" characters
And the line should end here ($ character)
Feb 19 '11 #2

P: 80
Wow! Suddenly made alot more sense.. Thanks that helped alot!
Feb 20 '11 #3

P: 80
Couldn't make any matches with
Expand|Select|Wrap|Line Numbers
  1. ^<span.*?>(\d*\.\d*).*<\/span>$
Please note I use VBScript version 5.8
Feb 22 '11 #4

P: 80
OH I found the problem.. The think Is it is loaded from a HTML source and theres more characters on the entire line wich looks like this:

Expand|Select|Wrap|Line Numbers
  1. <div id=currency_converter_result>320 GBP = <span class=bld>2816.6400 DKK</span> 
Feb 22 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.