ack (perl?) regexp matching lines where if is the first word
Posted
by Gauthier
on Stack Overflow
See other posts from Stack Overflow
or by Gauthier
Published on 2010-04-14T15:15:15Z
Indexed on
2010/04/14
15:33 UTC
Read the original article
Hit count: 331
Hey. I'm finally learning regexps, training with ack. I believe this uses perl regexp.
I want to match all lines where the first non-blank characters are if (<word> !
, with any number of spaces in between the elements.
This is what I came up with:
^[ \t]*if *\(\w+ *!
It only nearly worked. ^[ \t]*
is wrong, since it matches one or none [space or tab].
What I want is to match anything that may contain only space or tab (or nothing).
For example these should not match:
// if (asdf != 0)
else if (asdf != 1)
How can I modify my regexp for that?
© Stack Overflow or respective owner