Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Help with REGEX match cases

Help with REGEX match cases

Scheduled Pinned Locked Moved C#
regexjsonhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jeweladdict
    wrote on last edited by
    #1

    Can you guys tell me if these are correct? I'm parsing a file, word by word, and I'm trying to see if they fit into the correct format. The first format is if the token is a double. Meaning we have 1234 or 1234.0123 What I have is if( (Regex.IsMatch( token, @"\d*")) || (Regex.IsMatch( token, @"\d*[.]\d*")) ) The second is if it is a letter followed by any other alphanumeric up to 10 characters total in length: if( Regex.IsMatch( token, @"\b[a-zA-z]\w{2,3,4,5,6,7,8,9}\b") ) Do those look right? Thanks in advance!

    C 1 Reply Last reply
    0
    • J jeweladdict

      Can you guys tell me if these are correct? I'm parsing a file, word by word, and I'm trying to see if they fit into the correct format. The first format is if the token is a double. Meaning we have 1234 or 1234.0123 What I have is if( (Regex.IsMatch( token, @"\d*")) || (Regex.IsMatch( token, @"\d*[.]\d*")) ) The second is if it is a letter followed by any other alphanumeric up to 10 characters total in length: if( Regex.IsMatch( token, @"\b[a-zA-z]\w{2,3,4,5,6,7,8,9}\b") ) Do those look right? Thanks in advance!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      jeweladdict wrote:

      What I have is if( (Regex.IsMatch( token, @"\d*")) || (Regex.IsMatch( token, @"\d*[.]\d*")) )

      You can do this with one regex @"\d*([.]\d*)?"

      jeweladdict wrote:

      if( Regex.IsMatch( token, @"\b[a-zA-z]\w{2,3,4,5,6,7,8,9}\b") )

      YOu can shorten {2,3,4,5,6,7,8,9} to {2, 9}. Expresso is the program you need to test your regex, just google it, I think it's on CP tho. Christian Graus - Microsoft MVP - C++

      J 1 Reply Last reply
      0
      • C Christian Graus

        jeweladdict wrote:

        What I have is if( (Regex.IsMatch( token, @"\d*")) || (Regex.IsMatch( token, @"\d*[.]\d*")) )

        You can do this with one regex @"\d*([.]\d*)?"

        jeweladdict wrote:

        if( Regex.IsMatch( token, @"\b[a-zA-z]\w{2,3,4,5,6,7,8,9}\b") )

        YOu can shorten {2,3,4,5,6,7,8,9} to {2, 9}. Expresso is the program you need to test your regex, just google it, I think it's on CP tho. Christian Graus - Microsoft MVP - C++

        J Offline
        J Offline
        jeweladdict
        wrote on last edited by
        #3

        @"\d*([.]\d*)?" seems to work for IP addresses as well. I tried using the @"\b\d*([.]\d*)?\b" but that didn't seem to help. I'm only looking for numbers that are possible doubles. Any ideas?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups