LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-30-2009, 08:59 AM   #1
neioo
LQ Newbie
 
Registered: Jan 2008
Location: Sant Quinti de Mediona
Distribution: Gentoo
Posts: 24

Rep: Reputation: 2
regular expressions using flex: max and min length


Hello,

I'm using flex and bison to check the correctness of a username, so I have this regexp:
Code:
[A-za-z0-9]+([\.\-]?[A-Za-z0-9]+)*
This works ok for me: usernames start with a letter or number and can have '.' and '-' surrounded by at least one letter or number.

But now, I want to set a minimum and a maximum length of the username, I tried:
Code:
([A-za-z0-9]+([\.\-][A-Za-z0-9]+)*){3,22}
But this doesn't work, because it counts the number of times that the regexp is applied and not count the number of characters of the array.

Is there a way to apply two regexp at same time? like an "and" operator, if so, I could use something like:
Code:
[A-za-z0-9]+([\.\-]?[A-Za-z0-9]+)* AND .{3,22}
Or is there a way to count total characters of an input and apply a regexp at same time?

I think it must be easy to do, but by now my solution is to first check length with strlen and then check correctness using flex.

One link to a webpage lighting the solution will be ok, you don't need to give me the correct regexp.

Thanks in advance.

Last edited by neioo; 07-30-2009 at 09:53 AM.
 
Old 07-30-2009, 08:51 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,455

Rep: Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843Reputation: 843
Maybe you can use yylen (see User Values). I don't think there is any simple way of AND'ing two regexps together, even though regular languages are closed under intersection.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please Help Change Password Min Length from 6 to 8 mccartjd Linux - Newbie 3 05-08-2008 06:00 AM
regular expressions. stomach Linux - Software 1 02-10-2006 06:41 AM
Min/Max buttons? andykap Linux - General 3 12-15-2003 12:09 AM
Can't Change Min Password Length in RHL7.2 MikHud Linux - Security 2 04-16-2002 05:36 AM


All times are GMT -5. The time now is 04:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration