Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 8th, 2009, 08:44 AM
endersending endersending is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 122 endersending User rank is Lance Corporal (50 - 100 Reputation Level)endersending User rank is Lance Corporal (50 - 100 Reputation Level)endersending User rank is Lance Corporal (50 - 100 Reputation Level) 
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

Reply With Quote
  #2  
Old May 8th, 2009, 08:57 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Sarcky
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,923 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 1 Day 11 h 1 m 28 sec
Reputation Power: 6113
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.

Reply With Quote
  #3  
Old May 8th, 2009, 09:12 AM
endersending endersending is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 122 endersending User rank is Lance Corporal (50 - 100 Reputation Level)endersending User rank is Lance Corporal (50 - 100 Reputation Level)endersending User rank is Lance Corporal (50 - 100 Reputation Level) 
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

Reply With Quote
  #4  
Old May 8th, 2009, 12:20 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Sarcky
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,923 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 1 Day 11 h 1 m 28 sec
Reputation Power: 6113
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

Reply With Quote
  #5  
Old May 8th, 2009, 01:55 PM
endersending endersending is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 122 endersending User rank is Lance Corporal (50 - 100 Reputation Level)endersending User rank is Lance Corporal (50 - 100 Reputation Level)endersending User rank is Lance Corporal (50 - 100 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Help building a quick expression

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap