Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

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


I'm using flex and bison to check the correctness of a username, so I have this regexp:
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:
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:
[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 10:53 AM.
Old 07-30-2009, 09:51 PM   #2
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,240

Rep: Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406Reputation: 1406
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.


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 07:00 AM
regular expressions. stomach Linux - Software 1 02-10-2006 07:41 AM
Min/Max buttons? andykap Linux - General 3 12-15-2003 01:09 AM
Can't Change Min Password Length in RHL7.2 MikHud Linux - Security 2 04-16-2002 06:36 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:50 AM.

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