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
  1. Home
  2. General Programming
  3. C#
  4. Regex Question: How to search for "$"...

Regex Question: How to search for "$"...

Scheduled Pinned Locked Moved C#
regextutorialquestion
8 Posts 6 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.
  • N Offline
    N Offline
    Nitron
    wrote on last edited by
    #1

    Can someone give me an example pattern that matches: $1.25 I can't seem to figure out how to match a literal "$" as it's not a valid escape character... Thanks!

    ~Nitron.


    ññòòïðïðB A
    start

    E G D D E 5 Replies Last reply
    0
    • N Nitron

      Can someone give me an example pattern that matches: $1.25 I can't seem to figure out how to match a literal "$" as it's not a valid escape character... Thanks!

      ~Nitron.


      ññòòïðïðB A
      start

      E Offline
      E Offline
      ednrgc
      wrote on last edited by
      #2

      have you tried: \$\d

      1 Reply Last reply
      0
      • N Nitron

        Can someone give me an example pattern that matches: $1.25 I can't seem to figure out how to match a literal "$" as it's not a valid escape character... Thanks!

        ~Nitron.


        ññòòïðïðB A
        start

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        The $ character has a special meaning in regular expression (matching the end of the string). Use \$ to match a literal $.

        --- Year happy = new Year(2007);

        1 Reply Last reply
        0
        • N Nitron

          Can someone give me an example pattern that matches: $1.25 I can't seem to figure out how to match a literal "$" as it's not a valid escape character... Thanks!

          ~Nitron.


          ññòòïðïðB A
          start

          D Offline
          D Offline
          Dustin Metzgar
          wrote on last edited by
          #4

          Nitron wrote:

          match a literal "$" as it's not a valid escape character...

          As the other responses suggest, you should be able to escape the $. An alternative is to put it like this: [$]  instead of escaping it.

          Logifusion[^]

          1 Reply Last reply
          0
          • N Nitron

            Can someone give me an example pattern that matches: $1.25 I can't seem to figure out how to match a literal "$" as it's not a valid escape character... Thanks!

            ~Nitron.


            ññòòïðïðB A
            start

            D Offline
            D Offline
            Daniel Grunwald
            wrote on last edited by
            #5

            You have to distinguish between Regex escape characters and C# escape characters. If you escape a character for a Regex, you have to prefix it with a \. To write a \ in C#, you'll have to add another \. So you'll have to use "\\$" or @"\$" in C#

            N 2 Replies Last reply
            0
            • N Nitron

              Can someone give me an example pattern that matches: $1.25 I can't seem to figure out how to match a literal "$" as it's not a valid escape character... Thanks!

              ~Nitron.


              ññòòïðïðB A
              start

              E Offline
              E Offline
              Ennis Ray Lynch Jr
              wrote on last edited by
              #6

              You may be able to just use Decimal.Parse if all you have is a money string.


              File Not Found

              1 Reply Last reply
              0
              • D Daniel Grunwald

                You have to distinguish between Regex escape characters and C# escape characters. If you escape a character for a Regex, you have to prefix it with a \. To write a \ in C#, you'll have to add another \. So you'll have to use "\\$" or @"\$" in C#

                N Offline
                N Offline
                Nitron
                wrote on last edited by
                #7

                Daniel Grunwald wrote:

                So you'll have to use "\\$" or @"\$" in C#

                ahh... that makes sense. I was getting an error with \$, saying it wasnt an escape char, but \\$ might work... I'll try it tomorrow, thanks!

                ~Nitron.


                ññòòïðïðB A
                start

                1 Reply Last reply
                0
                • D Daniel Grunwald

                  You have to distinguish between Regex escape characters and C# escape characters. If you escape a character for a Regex, you have to prefix it with a \. To write a \ in C#, you'll have to add another \. So you'll have to use "\\$" or @"\$" in C#

                  N Offline
                  N Offline
                  Nitron
                  wrote on last edited by
                  #8

                  That [\\$] was it! Thanks, I would have never thought of that.

                  ~Nitron.


                  ññòòïðïðB A
                  start

                  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