abrari loves her mum :-)
So when I’m at work I sometimes hear, “oh you’ll like this, it accepts regular expressions,” and everyone goes “whooooo!” and I think “oh yeah, great… yeah … I don’t know regular expressions.”
abrari loves her mum :-)
So when I’m at work I sometimes hear, “oh you’ll like this, it accepts regular expressions,” and everyone goes “whooooo!” and I think “oh yeah, great… yeah … I don’t know regular expressions.”
This is one skill that I am constantly using at work. I refuse to work with editors that don’t give me immediate access to regex.
Check out CPAN for the Perl module called Regex::Common. It has pre-built regexes for many common things so that you don’t have to bang your head against the wall.
http://search.cpan.org/dist/Regexp-Common/
e.g: # we require that $replacement be JUST a valid IP address
die “Invalid IP address provided: [$replacement]”
unless $replacement =~ m/^$RE{net}{IPv4}$/;
I can’t believe I went for some eight years without knowing these existed. Now that I’ve learned it, there’s rarely a day that I don’t use it.
I’m taking a Unix Topics course at the university and the class will spend about 2 weeks learning regular expressions. I don’t expect to master them in that time, but I will probably want to later on. Once I get a basic understanding of them, I anticipate learning more on my own.
http://www.wilsonmar.com/1regex.htm
There are a lot of good examples, like matching IP addresses and MAC addresses.
First, I read this guide.
Next, here’s an example to puzzle over:
sentence.gsub( /\([-\w]+\)/, ’’ )
This example will find the literal parens characters with one or more words in between and replace them with nothing.
The trick is to remember that they’re not confusing as long as you don’t think about them. Once you start thinking about them they get confusing. Just take a step back and try not to rack your brain.
$line =~ s/\027-\036\004-\025\376\377//gi;
maybe if i ignore it it will go away…
(if i have my head on straight, this replaces several nonprintable charachters with nothingness)
edit: http://www.weitz.de/regex-coach/ <—made of pure awesome