The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Help building a quick expression
Discuss Help building a quick expression in the Regex Programming forum on Dev Shed. Help building a quick expression Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 8th, 2009, 08:44 AM
|
|
Contributing User
|
|
Join Date: May 2008
Posts: 122
 
Time spent in forums: 17 h 1 m 9 sec
Reputation Power: 6
|
|
|
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
|

May 8th, 2009, 08:57 AM
|
 |
Sarcky
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|

May 8th, 2009, 09:12 AM
|
|
Contributing User
|
|
Join Date: May 2008
Posts: 122
 
Time spent in forums: 17 h 1 m 9 sec
Reputation Power: 6
|
|
|
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
|

May 8th, 2009, 12:20 PM
|
 |
Sarcky
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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
|

May 8th, 2009, 01:55 PM
|
|
Contributing User
|
|
Join Date: May 2008
Posts: 122
 
Time spent in forums: 17 h 1 m 9 sec
Reputation Power: 6
|
|
|
Solved
Quote: | 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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|