Results 1 to 3 of 3

Thread: [RESOLVED] [RegEx] Double

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,698

    Resolved [RESOLVED] [RegEx] Double

    I'm trying to match a double. Here is my railroad diagram of how I want the RegEx to preform:
    Name:  Decimal Diagram.png
Views: 115
Size:  3.7 KB

    Here is the RegEx I'm attempting:
    Code:
    \d+(\.\d)?
    My issue is that the RegEx doesn't allow for the optional negative sign at the beginning of the number.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: [RegEx] Double

    This seem to work:

    Code:
    Imports System.Text.RegularExpressions
    
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim pattern As String = "^[+-]?\d+(\.\d+)?$"
    
            MessageBox.Show(Regex.IsMatch("123", pattern))
            MessageBox.Show(Regex.IsMatch("123.1", pattern))
            MessageBox.Show(Regex.IsMatch("123.b", pattern))
            MessageBox.Show(Regex.IsMatch("-123.1", pattern))
        End Sub
    End Class
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,698

    Re: [RegEx] Double

    Thank you so much!
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width