john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

Regular expressions tutorial

regular-expressions-tutorial

Regular expressions are a more advanced way for software to find a given text pattern

normally you can give a simple search and most software (editors, browsers, etc.) will be able to list matches... I used notepad2 to write this document AND to test my regular expresions.

e.g. find -name 'filename' //this will find files containing "filename" as their name

Generally these searches are case insensitive.

To make the software only return the precise results we desire we might want case sensitive search or...

WILD CARDS allow the software to match anything before or after a specific criteria

A //finds in some file or body of text a word with any characters then capital A then any characters

ANCHORS tell the software that the desired specific character or string is in a specific location

^fi //the file begins with fi, could be filename1, or filename2, or fiGGY

grep 'end.$' file.txt //the text ends with "end", like the end

^shortline$ //only a line that contains exactly "shortline" will be returned

WORD ANCHORS allow you to pick out specific beginnings or ends of a word (not including newlines, spaces or symobls)

\<find //will return results from *find but not afind

found> //will return results from newfound but not newfoundland

\<specific> //will only return results where specific doesn't have any letters around it

CHARACTER POSITION

f[iou]nd //this will find fond fund f[1-9a-f] //this will find f9d but not f0d or f9g


  • « Slackware backtrack service sshd restart
  • Php execute linux script with arguments passthru escapeshellarg »

Published

Feb 6, 2010

Category

linux

~239 words

Tags

  • expressions 2
  • linux 249
  • regular 5
  • tutorial 6