Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > BOOK: Beginning Regular Expressions
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Regular Expressions
This is the forum to discuss the Wrox book Beginning Regular Expressions by Andrew Watt; ISBN: 9780764574894
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Regular Expressions section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 5th, 2009, 03:22 AM
Registered User
 
Join Date: Feb 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default regular expression-- needed help

i have this: ^(?!.*--)[A-Za-z\d-]+$
it accepts alphanumeric characters, optionally with single dash only and it does not accepts space.

now i need it to accept space for example:
ab34 12435, ab34- 12435 is valid.
ab34 12435, ab34- 12435 is invalid.

never mind the space before and end of the example.. i can trim that before i validate it to my problem regular expression

any help please
  #2 (permalink)  
Old September 5th, 2009, 04:33 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I'm sorry, but I can't see *ANY* difference between you valid and invalid examples.

I even used "view==>>source" to see your post, in case the forum was "eating" some characters, and they are identical. Thus:
Code:
ab34 12435, ab34- 12435 is valid. <br />
ab34 12435, ab34- 12435 is invalid.<br />
Try again??
  #3 (permalink)  
Old September 5th, 2009, 08:58 PM
Registered User
 
Join Date: Feb 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it needs to accept alphanumeric with optionally a non-consecutive dash and optionally a non-consecutive space.

it accepts:
12a-3c-4f3fg
12ertgg2
1-2-3-3-4-3
dffgsfg
d-f-f-g-s-f-g

it does not accept:
12-3c-4f&3fg
12e%rt-gg2
d--f-f-g-s-f-g
1-2-3-3-4--3
  #4 (permalink)  
Old September 6th, 2009, 03:51 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Wish you had given more *different* examples.

Non-consecutive dash or space, okay. But what about dash followed by space or vice versa?
And can the sequence begin or end with a dash or space??
Code:
a1 -b2
c3- d4
-e5-f6
g7-h8-
Are any/all of those valid???

Anyway...assuming that *NONE* of those are legal:
Code:
/^([a-z0-9]+[ \-])*[a-z0-9]+$/i
I think that does it. That's JavaScript regexp notation.

You see it?
Code:
/^ === start
([a-z0-9]+[ \-])* === zero or more of
     [a-z0-9]+  === one or more alphanums
     [ \-]  === followed by either space or dash
[a-z0-9]+  === ending with one or more alphanums
$  === end 
/i  === ignore case of alphas
  #5 (permalink)  
Old September 6th, 2009, 09:39 PM
Registered User
 
Join Date: Feb 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you sooooo much sir. i really appreciate it..
 


Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression Help Please rstelma ASP.NET 1.0 and 1.1 Professional 0 January 2nd, 2008 06:01 PM
regular expression if-then smay Javascript 4 July 5th, 2005 12:10 PM
Regular Expression Help anshul PHP How-To 4 December 8th, 2004 04:19 AM
Regular Expression Help Greg Griffiths Javascript How-To 4 November 12th, 2004 04:33 AM
help in regular expression diby Beginning PHP 1 September 17th, 2003 12:25 PM



All times are GMT -4. The time now is 02:04 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.