Tag Archives: regex

My most used Perl regular expressions.

Match full path of image and extention and store in an array. my @arr = ($string =~ m/([\/A-Za-z0-9_\-]+\.(?:jpg|png))/g); Add something to the end of a line. $string =~ s/(.*)/$1 something/; Add something to the beginning of a line. $string =~ s/(.*)/something $1/; Match an HTML <img> tag. $string =~ m/(<img.*?>)/;
Posted in Programming, Webhosting | Also tagged | Leave a comment

Removing leading whitespace in file with perl.

Do you ever have code with such poor formatting that you just need to start over? This will let you remove all leading whitespace from every line in the file. I’ve found it handy every now and then. perl -i -pe's/^\s+//' file.c
Posted in Programming, Webhosting | Also tagged , | Leave a comment

My most used VIM regular expressions.

Delete all lines in a file except those that start with “#”. :g/^[^#].*$/d Text search/replace. Transform line ‘wget http://gnucom.cc/some_backup.tar.gz’ into ‘/scripts/restorepkg some_backup.tar.gz’. This one is helpful for cPanel administrators. :%s/wget http:.*\//\/scripts\/restorepkg /g Add something to the end of every line of a file. :%s/$/something/g Add something to the beginning of every line of a file. [...]
Posted in Webhosting | Also tagged | Leave a comment