The Start of Word Sequence

The \< sequence is used to match the start of a word boundary in a regular expression search. For example, given the code below,

 

#define threshold_low        2400

#define threshold_high       4800

#define threshold_mid        3600

#define enable_threshold_lev 1

 

If we wanted to match the three threshold levels but not the enable_threshold_lev, we could use the following expression:

 

\<threshold_[A-Za-z]+[ \t]+[0-9]+

 

This expression will match the following:

 

#define.threshold_low        2400.

#define.threshold_high       4800.

#define.threshold_mid        3600.

#define enable_threshold_lev 1.

 

Understanding the Expression

Let's break down the expression to understand how it works. The first part is highlighted below:

 

\<threshold_[A-Za-z]+[ \t]+[0-9]+

 

This sequence means match any sequences of threshold_ that marks the beginning of a word as indicated by the \< sequence. Note that the enable_threshold_lev is not highlighted because the threshold_ sequence does not define the beginning of a word. Thus we would get the following three matches:

 

#define.threshold_low        2400.

#define.threshold_high       4800.

#define.threshold_mid        3600.

#define enable_threshold_lev 1

 

The second part,

 

\<threshold_[A-Za-z]+[ \t]+[0-9]+

 

extends our match to find one or more characters in the set A-Z, a-z. Thus our new match would look like:

 

#define.threshold_low        2400.

#define.threshold_high       4800.

#define.threshold_mid        3600.

#define enable_threshold_lev 1

 

This still doesn't get our entire selection so we extend it to match any whitespace characters that separate our threshold name and its defined value as follows

 

\<threshold_[A-Za-z]+[ \t]+[0-9]+

 

which yields the selection:

 

#define.threshold_low........2400.

#define.threshold_high.......4800.

#define.threshold_mid........3600.

#define enable_threshold_lev 1

  

The last part of the expression extends the selection to match the value of the threshold as follows:

 

\<threshold_[A-Za-z]+[ \t]+[0-9]+

 

giving us our final selection:

 

#define.threshold_low........2400..

#define.threshold_high.......4800..

#define.threshold_mid........3600..

#define enable_threshold_lev 1

 

 

Back: End of Line

Forward: End of Word