Rules of motif forming
A motif is a pattern that you discover in a structure by analysis. For example, common sequence motifs are short sequence fragments with parts similar to a regular expression. So, if you have a motif like "A*C" this matches to the sequences "AAC" and "ACC" but not to "ACA". You can reverse the process to discover the motif from the sequences.

Similarly with structural motifs in proteins. A beta-hairpin is :


  The motif consists of two strands that are adjacent in primary
  structure, oriented in an antiparallel direction ... and linked by a
  short loop of two to five amino acids.


So first you have to determine where the strands and loops are, then how the strands are connected into sheets, and finally recognise the hairpins. It is the definition of the motif itself that determines how you discover it.

Some resources that might be helpful are:


Motivated proteins (Small h-bonded motifs)
The protein topology graph library (Larger motifs)
The protein geometry database (Not really motifs, but interesting)
PDBeMotif (define and search for motifs in the PDB)