regex to remove leading zeros and hypens?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Smokey Grindel

    #1

    regex to remove leading zeros and hypens?

    I basically need to remove any leading zeros and hyphens from a string...
    regex seemed like the best rout and using a replace regex method... anyone
    know of any good strings for this? The one I just made quick is ^0+|[-] but
    not having much experience with regex, is this the correct one?

  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

    #2
    Re: regex to remove leading zeros and hypens?

    Smokey Grindel wrote:
    I basically need to remove any leading zeros and hyphens from a
    string... regex seemed like the best rout and using a replace regex
    method... anyone know of any good strings for this? The one I just made
    quick is ^0+|[-] but not having much experience with regex, is this the
    correct one?
    I would make a set that matches either a zero or a hyphen:

    ^[0\-]+

    That could be used to replace this:

    0--000-----0hello

    into:

    hello

    Perhaps you want it to be more specific, like removing an optional
    single hyphen followed by any number of zeroes?

    ^-?0*

    This could be used to replace this:

    -00001123

    into:

    1123

    but it would leave this:

    -00----00000Hi

    as:

    ----00000Hi

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • eBob.com

      #3
      Re: regex to remove leading zeros and hypens?

      "Smokey Grindel" <nospam@nospam. comwrote in message
      news:eoM7bJ0QJH A.4680@TK2MSFTN GP06.phx.gbl...
      >I basically need to remove any leading zeros and hyphens from a string...
      >regex seemed like the best rout and using a replace regex method... anyone
      >know of any good strings for this? The one I just made quick is ^0+|[-] but
      >not having much experience with regex, is this the correct one?
      Your query is somewhat light on specifics, but if you have strictly leading
      zeros and hyphens I think I would use String.TrimStar t. That strikes me as
      more straightforward than a regex replace. But if you want to play with
      regex expressions get Expresso from UltraPico. It's free.

      Bob


      Comment

      Working...