468,505 Members | 1,778 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

RegEx.. Finding pattern?

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)

4 1975
Monomachus
127 Expert 100+
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
Pheddy
80
Wow! Suddenly made alot more sense.. Thanks that helped alot!
Feb 20 '11 #3
Pheddy
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
Pheddy
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.

Similar topics

4 posts views Thread by Han | last post: by
3 posts views Thread by Beeeeeves | last post: by
1 post views Thread by Lee Kuhn | last post: by
1 post views Thread by Craig Kenisston | last post: by
9 posts views Thread by Whitless | last post: by
reply views Thread by Marcel Stör | last post: by
5 posts views Thread by redamazon200 | last post: by
2 posts views Thread by John B | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.