RegEx.. Finding pattern?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pheddy
    New Member
    • Dec 2008
    • 80

    RegEx.. Finding pattern?

    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:
    Code:
    <span class=bld>2832.1600 USD</span>
    I would need to extract the number 2832.1600

    Thanks!
    Frederik
  • Monomachus
    Recognized Expert New Member
    • Apr 2008
    • 127

    #2
    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
    Ruby-based regular expression editor/tester


    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)

    Comment

    • Pheddy
      New Member
      • Dec 2008
      • 80

      #3
      Wow! Suddenly made alot more sense.. Thanks that helped alot!

      Comment

      • Pheddy
        New Member
        • Dec 2008
        • 80

        #4
        Couldn't make any matches with
        Code:
        ^<span.*?>(\d*\.\d*).*<\/span>$
        Please note I use VBScript version 5.8

        Comment

        • Pheddy
          New Member
          • Dec 2008
          • 80

          #5
          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:

          Code:
          <div id=currency_converter_result>320 GBP = <span class=bld>2816.6400 DKK</span>

          Comment

          Working...