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

Please HELP!!!!!!!!!!

Last post 11-04-2009, 12:59 PM by mash. 2 replies.
Sort Posts: Previous Next
  •  11-04-2009, 6:23 AM 57132

    Please HELP!!!!!!!!!!

    I need to write a regular expression to match continous numbers like 1234,56789 or 3456 .Please help.Im stuck in this from past 4 days.I am not very good at regexp.I need the expression very badly!
  •  11-04-2009, 12:48 PM 57139 in reply to 57132

    Re: Please HELP!!!!!!!!!!

    You need to understand that numbers have no meaning to a regex.  Regexes only understand characters. So the numeral value of the digits isn't understood.

    The following will match the sample you provided, as well as single digits. But would fail on an alphanumeric string like "abc123".  Plus you'll get empty match before numbers that don't fit the pattern.

    Raw Match Pattern:
    \b(?=\d)0?1?2?3?4?5?6?7?8?9?\b

    $matches Array:
    (
        [0] => Array
            (
                [0] => 1234
                [1] => 56789
                [2] => 3456
            )

    )


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  11-04-2009, 12:59 PM 57140 in reply to 57139

    Re: Please HELP!!!!!!!!!!

    Actually this pattern would  be better

    Raw Match Pattern:
    \b(?:(?:01?2?3?4?5?6?7?8?9?)|(?:12?3?4?5?6?7?8?9?)|(?:23?4?5?6?7?8?9?)|(?:34?5?6?7?8?9?)|(?:45?6?7?8?9?)|(?:56?7?8?9?)|(?:67?8?9?)|(?:78?9?)|(?:89?)|9)\b

    $matches Array:
    (
        [0] => Array
            (
                [0] => 1234
                [1] => 56789
                [2] => 3456
            )

    )


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
View as RSS news feed in XML