Dec 15 2006

Regex Notes

Category: SoftwareDmitry @ 8:29 pm

Regular expressions (regex) let you search for a particular pattern. Regex consist of literal characters, and special characters, also called meta characters. Regex syntax has 2 modes, one inside of character classes, which is inside [ ] and one outsided of character classes.

Character classes []:  Regex inside [] are in different mode and have different syntax. It matches a  single character specified as a list, range or class shortcut.  03[-./]19[-./]76  Will match the above date delimited by a dot or a hyphen.  Inside [] the dot is no longer a meta-character, its matched literally!  Negation Operator ^  f[^u]  matches something with f, followed by any character other then u  Character classes shortcuts  \d [0-9] digit  \D non digit  \w [a-zA-Z0-9_] part of word  \W non word  \s [ \t\n\r\f\v] whitespace  \S non whitespaceAlternation:  | operator is 'or'  Jeff(re|er|izz)y  => Jeffrey, Jeffery, JeffizzyConditionals:  (?if then | else)  if the "if" part is true, "then" expression is attmpted, otherwise  "else" is attempted  (?if then)  else condition is optional, so is the pipe character prefixing itAnchors:  ^  beg of line  $  end of line  \b word boundary  \B non-word boundary  Ruby:  \A begining of a string  \Z end of string (or before newline at the end)  \z end of stringOptional Items:  ? optionally matches a character before it, or you can specify a group() of  characters before it:  colou?r  will match color and colour  4(th)?  will match 4 and 4thRepetitions:  +            s1 or more times  *            0 or more times  ?            1 or 0 times  {n}          match exactly n times  {min, max}   min to max times  {min,}       at least min  {,max}       at most max (ruby)Backreferences:  First matched group ():    sed, vi: \1    ruby: $1    php: $m[1]    python, java: m.group(1)    c#: m.Groups[1]  Group zero is typically the entire matchEscape:  \. will escape dot meta characterMore Info:  http://www.regular-expressions.info/

14 Responses to “Regex Notes”

  1. Ash women leather boot says:

    This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It’s the old what goes around comes around routine.

  2. Wholesale Jerseys says:

    I’m still learning from you, as I’m trying to achieve my goals. I certainly liked reading everything that is posted on your site.Keep the information coming. I enjoyed it

  3. abercrombie deutschland says:

    abercrombie deutschland

  4. abercrombie and fitch uk says:

    abercrombie and fitch uk

  5. burberry outlet says:

    burberry outlet

  6. burberry uk says:

    burberry uk

  7. essay topics says:

    what a great post! i really like it and wanted to say thanks for sharing!

  8. http://www.mulberryoutletsb.co.uk/ says:

    If you are looking at purchasing on your own Mulberry Outlet bags that are the perfect example for luxurious, modernity and trend then you definitely should check out the latest assortment of Mulberry Handbags. These baggage will certainly treat all your senses, and you will probably not just look like but in addition seem like a way superstar.

  9. wallpapers for desktop says:

    I certainly liked reading everything that is posted on your site.Wallpapers 1012 Keep the information coming. I enjoyed it

  10. academic freelancing says:

    Great work! Thanks for sharing.

  11. Jordans Cheap says:

    555yxj
    This is highly informatics, crisp and clear. I think that Everything has been described in systematic manner so that reader could get maximum

  12. cheap north face jackets says:

    I firmly believe that if you follow a path that interests you,
    Not to the exclusion of love, cheap north face jackets sensitivity, and cooperation with others

  13. Cheap Oakley Sunglasses says:

    Pick out and buy your Cheap Oakley Sunglasses on our website is a wise choice for you.
    Here Oakley Sunglasses Sale is available in various fashionable styles and colors,
    all of which are prevalent for the most popular designs and latest styles.
    We are a professional Wholesale Oakley Sunglasses online store,
    offering a large number of Cheap Oakley Sunglasses and Replica Oakley Sunglasses with best price,
    free of tax. Each sunglass has its own features to meet all people’s different needs and give the best protection for your beautiful eyes.
    Purchase fashionable Cheap Oakley Sunglasses at our online store! We also offer fast delivery, and excellent service within workdays.
    Welcome to our website to look and shop!

  14. cheap ray ban sunglasses says:

    i am extremely impressed with your writing skills and also with the design of your blog.

Leave a Reply