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

splitting floats

Last post 05-07-2008, 7:37 PM by Aussie Susan. 2 replies.
Sort Posts: Previous Next
  •  05-07-2008, 1:43 AM 41974

    splitting floats

    For some reason, I'm having a hard time trying to split the string

        -3.833306074E+0-1.160855160E-15

     Anyone see anything wrong w/ what I have?

    [-+][\d.]*(?:E[-+]\d+)?

     It seems like all I'm getting is this ... -3.833306074E

     Any help much appreciated.
     

  •  05-07-2008, 11:35 AM 41996 in reply to 41974

    Re: splitting floats

    Raw Match Pattern:
    [-+][\d.]*(?:E[-+]\d+)?

    $matches Array:
    (
        [0] => Array
            (
                [0] => -3.833306074E+0
                [1] => -1.160855160E-15
            )

    )

  •  05-07-2008, 7:37 PM 42002 in reply to 41974

    Re: splitting floats

    Can I just clarify something with the terminology here: what function are you using to apply the pattern to the text?

    When dealing with regex's there are two distinctly different operations that you can use. One is matching where what you get back are the subset of characters that match the pattern from within the text.

    The other is splitting where the pattern is used to create multiple results by, in effect, finding the text given by the pattern and returning the two pieces of text on either side of the match but NOT including the match itself. Think of it as replacing the matched text with a newline when you have multiple lines of text.

    The only way I can get something like what you have said is happening is to modify the pattern to be

    [-+][\d.]*?(?:E[-+]\d+)?

    perform a split with the sample text you have provided where I get the following :

    NULL (occurs at the start of the string because the entire pattern is optional)
    3.833306074E  (the '-' was what was matched and so is where the split occurs)
    0
    1.160855160E
    15

    In effect this has found all of the +/- signs and split on those.

    Without further information on your language, regex etc (in fact the things that are asked for in the Posting Guidelines in the sticky note at the top of this forum) I can't think of anything else that would produce the output you describe.

    Susan
     

View as RSS news feed in XML