#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    122
    Rep Power
    7

    Help building a quick expression


    I have these IDs that i need to parse out...
    I need an expression to fit this:
    RYY-1264+00-NE120

    so .. Letters dash numbers dash or plus numbers dash letters/numbers
    and nothing else after it

    I have this:
    [a-zA-Z]+\-[0-9]+(\+|\-)[0-9]+\-[a-zA-Z0-9]+[^.]*

    but IDs like this still test true:
    RF-109+00-dC1 (IC36)


    Also, anyone know how i could get greek letters out of a string? i have to replace the greek characters alpha, beta, delta with the string equivelents (the alpha sign replaced with "alpha")

    Thanks!
    If you see darth vadar .. kick him in the nuts
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,905
    Rep Power
    6351
    your match is easier with:
    /^[a-z]+-\d+[+-]\d+-[a-z\d]+$/i

    As for your second question, you can use the hex notation of the characters I think, or you may be able to put them right into a replacement expression if your server supports unicode characters in code.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    122
    Rep Power
    7

    awesome


    it doesnt seem to work ..
    im testing it against this:
    RF-109+00-dC1


    I have a few question, if you dont mind, so i can understand this a little better:
    What does the forward slash do at the beginning .. and the $/i at the end?
    Also, for the [+-] should there be a logical OR in there? [+|-]?

    Thanks
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,905
    Rep Power
    6351
    MOST regular expression parsers expect the regular expression to be "bound" by a character, usually the forward slashes that I've used here. The opening / is the start of the expression.

    A dollar sign "anchors" the expression to the end of the match string, so ending the expression in a dollar sign means nothing may come after the match.

    The / at the end ends the expression. After the ending / you can put flags that modify your expression.

    The "i" after the closing / tells the parser that this expression is case-insensitive, which allows you to use a-z instead of a-zA-Z. Makes it easier to read, is all.

    There should not be a logical OR inside a character class, character classes are OR by default. [aeiou] will match ANY of the vowels.

    What language are you using where you don't need delimiters on your patterns? If you're using PHP, do NOT use the ereg_ functions, they're deprecated.

    -Dan

    Comments on this post

    • prometheuzz agrees
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    122
    Rep Power
    7

    Solved


    Originally Posted by ManiacDan
    MOST regular expression parsers expect the regular expression to be "bound" by a character, usually the forward slashes that I've used here. The opening / is the start of the expression.

    A dollar sign "anchors" the expression to the end of the match string, so ending the expression in a dollar sign means nothing may come after the match.

    The / at the end ends the expression. After the ending / you can put flags that modify your expression.

    The "i" after the closing / tells the parser that this expression is case-insensitive, which allows you to use a-z instead of a-zA-Z. Makes it easier to read, is all.

    There should not be a logical OR inside a character class, character classes are OR by default. [aeiou] will match ANY of the vowels.

    What language are you using where you don't need delimiters on your patterns? If you're using PHP, do NOT use the ereg_ functions, they're deprecated.

    -Dan
    Im writing this in VBA .. translation some IDs and cleaning up some unicode text.

    Here is the expression i used:
    [a-zA-Z]+-\d+[+|-]\d+-[a-zA-Z0-9]+$
    That works great.

    And then for the Greak letters:
    Dim regexBeta As String
    regexBeta = "\u03B2"
    Dim regexDelta As String
    regexDelta = "\u03B4"
    Dim regexAlpha As String
    regexAlpha = "\u03B1"

    Thanks for the help ... Your expression got me in the right direction, and helped alot.

IMN logo majestic logo threadwatch logo seochat tools logo