regular expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jdluk87
    New Member
    • Mar 2010
    • 5

    #1

    regular expression

    Hi,

    i should check if a username ($username) is like unix, so this username must start with a char, contains max 16 chars, all tiny and in general can contains just chars, numbers, and dot.

    all this with the use of regular expression.

    someone can help me?

    Thanks
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Sure, we can help you, but you are going to have to do the legwork so that you can learn. Try to write it and if you get stuck, post your code here so that we can see it and help you.

    Regards,

    Jeff

    Comment

    • jdluk87
      New Member
      • Mar 2010
      • 5

      #3
      i have a text file with a list of username, one for each row:

      jdluk87
      1isnotgood
      luca.lupo
      luca.lupo87
      .asd.luca12
      asd.sd---er.re

      the username ok are number: 1,3,4

      the second start with number so it's no good
      the fifth start with dot so it's no good
      the sisxt contains --- so it's no good,

      now if I do from console:

      grep '^[a-z][a-z0-9.]{3,16}$' example

      where example is name of my file, appear nothing.

      if i'll do:

      grep '^[a-z][a-z0-9.]' example:

      jdluk87
      luca.lupo
      luca.lupo87
      asd.sd---er.re

      so so...because appear a substring match such as asd.sd---er.re.

      So my problems are two:

      1. min and max of string that doesn't work
      2. problem with substring match.

      Edit/Delete Message

      Comment

      • toolic
        Recognized Expert New Member
        • Sep 2009
        • 70

        #4
        I answered this question on another forum:

        Comment

        • chaarmann
          Recognized Expert Contributor
          • Nov 2007
          • 785

          #5
          "grep" can only use basic regular expression That means no quantifiers (that you call "min and max of string"). Use "egrep" for full regular expression (or "sed" or "perl").

          Comment

          Working...