Monday, September 12, 2011

Searching code for a string not in the comments...

Every few months I need to search my code for a string but there are a bunch of references to that code in the comments and I want a regex that will remove those for me. I forget how to do it so every few months I have to figure it out again, well hopefully I will remember when I put it here:


>cat example.txt

token asdf asdf @OK
asdf token asdf @OK
//token @BAD
asdf token asdf // asdf token asdf @OK
// This is a token @BAD
/some/dir/token @OK
aaa token try again @OK
aaa token try again @OK
aaaa token try again @OK

>egrep '^.?([^/][^/])*token' example.txt

token asdf asdf @OK
asdf token asdf @OK
asdf token asdf // asdf token asdf @OK
aaaatoken try again @OK
aaa token try again @OK
aaaa token try again @OK

1 comment:

  1. Stephenmm,

    Did you ever figure out "How to auto syncronize files with network drive on Windows XP"? You had a question on superuser and I am struggling with the same issue.

    I have not had much luck searching the internet and any help would be great.

    Post back if you have questions or answers and I could provide an email address.

    Thanks,
    Ben

    ReplyDelete