Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Extracting a number out of a phrase

Last post 02-09-2010, 7:13 PM by macutan. 5 replies.
Sort Posts: Previous Next
  •  02-09-2010, 2:30 PM 59514

    Extracting a number out of a phrase

    i'm pretty new here...

    The platform I'm using is Yahoo! Pipes' Regex function -- documentation is here: http://pipes.yahoo.com/pipes/docs?doc=operators#Regex

    I need a regex that matches the price out of a text despription that always comes within the below form:

    Example main text:

    S$ 8,500 / month Negotiable, 1,237 sqft / 115 sqm (built-in) - Condominium, Cairnhill Rise (D09)

    need to extract: 8,500 (in number form so i can use it for later sorting)

    I have tried several stuff but with no success, see below:

    (.*\S$)(\d*)(.*) replace: $2

     

    Any guidance will be greatly appreciated.

    Macutan

  •  02-09-2010, 4:39 PM 59523 in reply to 59514

    Re: Extracting a number out of a phrase

    Raw Match Pattern:
    S\$\x20*(\d{1,3}(?:,\d{3})*)

    $matches Array:
    (
        [0] => Array
            (
                [0] => S$ 8,500
            )

        [1] => Array
            (
                [0] => 8,500
            )

    )

    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  02-09-2010, 4:58 PM 59524 in reply to 59523

    Re: Extracting a number out of a phrase

     

     mash!!!, thanks a lot for your prompt response, your regex works when y try it on http://www.gskinner.com/RegExr/ but when i put it on my yahoo pipe code it doesn't seem to work, it comes back as: 8,500 / month Negotiable, 1,237 sqft / 115 sqm (built-in) - Condominium, Cairnhill Rise (D09)

    see pipe address here: http://pipes.yahoo.com/pipes/pipe.info?_id=98485b176778798d46a8f0ed78b770ef (this particular regex is the one for the middle column of boxes).

     also is the number that you are capturing through this regex a number or text? (gskinner.com editor comes back with 8,500)...

     

    thanks once again for your input but i do not know what am i doing wrong... also how did you come up to your regex pattern? (years of experience?)

     macutan

     

     

  •  02-09-2010, 5:25 PM 59526 in reply to 59524

    Re: Extracting a number out of a phrase

    macutan:

     

     mash!!!, thanks a lot for your prompt response, your regex works when y try it on http://www.gskinner.com/RegExr/ but when i put it on my yahoo pipe code it doesn't seem to work, it comes back as: 8,500 / month Negotiable, 1,237 sqft / 115 sqm (built-in) - Condominium, Cairnhill Rise (D09)

    see pipe address here: http://pipes.yahoo.com/pipes/pipe.info?_id=98485b176778798d46a8f0ed78b770ef (this particular regex is the one for the middle column of boxes).

     also is the number that you are capturing through this regex a number or text? (gskinner.com editor comes back with 8,500)...

     

     I've never use Yahoo pipes before today so don't hold me to any of this.  Apparently it does a replace.

    With a regex replace you replace what was matched.  Anything that wasn't match is left untouched. So in the whole string only "S$ 8,500" is replaced by "8,500" which is not what you want. You want the entire line to be replaced so you have to match the entire line.

    Change the regex to

     S\$\x20*(\d{1,3}(?:,\d{3})*).+

    check the 's' in your regex module as well.

    Replace with

    $1

    macutan:

    thanks once again for your input but i do not know what am i doing wrong... also how did you come up to your regex pattern? (years of experience?)

     macutan

     

    Yes, several years

                         EXPLANATION

    ----------------------------------------------------------------------
      S                        'S'
    ----------------------------------------------------------------------
      \$                       '$'
    ----------------------------------------------------------------------
      \x20*                    character 32 (0 or more times (matching
                               the most amount possible))
    ----------------------------------------------------------------------
      (                        group and capture to \1:
    ----------------------------------------------------------------------
        \d{1,3}                  digits (0-9) (between 1 and 3 times
                                 (matching the most amount possible))
    ----------------------------------------------------------------------
        (?:                      group, but do not capture (0 or more
                                 times (matching the most amount
                                 possible)):
    ----------------------------------------------------------------------
          ,                        ','
    ----------------------------------------------------------------------
          \d{3}                    digits (0-9) (3 times)
    ----------------------------------------------------------------------
        )*                       end of grouping
    ----------------------------------------------------------------------
      )                        end of \1
    ----------------------------------------------------------------------
      .+                       any character except \n (1 or more times
                               (matching the most amount possible))
    ----------------------------------------------------------------------


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  02-09-2010, 6:46 PM 59530 in reply to 59526

    Re: Extracting a number out of a phrase

    mash:

     I've never use Yahoo pipes before today so don't hold me to any of this.  Apparently it does a replace.

    With a regex replace you replace what was matched.  Anything that wasn't match is left untouched. So in the whole string only "S$ 8,500" is replaced by "8,500" which is not what you want. You want the entire line to be replaced so you have to match the entire line.

    Correct, i think. what i would like is to replace the whole line and only have "8,500" as the price.

    Thanks mash, I know you don't specialized in yahoo pipes, but this doesn't seem to be working for some weird reason... :( see pipe address below, can anyone else see why this regex is not working in this case (see regex box in the middle column).

    thanks once again for all your help with this,... 

     pipe address: http://pipes.yahoo.com/pipes/pipe.info?_id=98485b176778798d46a8f0ed78b770ef

    NOTE: I just runned this new regex you sent me  S\$\x20*(\d{1,3}(?:,\d{3})*).+   on gskinner.com and woulnd't work unless i checked the "extended" checkbox,... but i cannot see that checkbox in yahoo pipes... anyone knows how i can do this?

     

     

  •  02-09-2010, 7:13 PM 59534 in reply to 59530

    Re: Extracting a number out of a phrase

     

     

    fixed it: i added: "(?x-ims:" to the regular expression and it worked in yahoo pipes. S\$\x20*(\d{1,3}(?:,\d{3})*).+)

     

    thanks! 

View as RSS news feed in XML