Jul 17, 2013, 11:28 PM
Post #2 of 2
The s/// operator is not a search operator, but a substitution operator. It should not be used in the context you discribed.
Re: [perlFun] Regex help: match word just to the right
[In reply to]
A regex is just a textual description of what you are looking for, with a few symbols to represent multiplie chartacters, alternation, etc.
But you need to described a bit more what you want to match. Suppose you just want to match a single letter on the right of the word module (separated by a space), you can do this:
my $line = 'Module A Serial Number: 8002276940\n';
my $matched_char = $1 if $line =~ /Module (\w)/;
"\w" represents any alphanumerix character, the parens () specify that you want to capture the content, and the capture is made into the $1 special variable (if there was a second set of parens, the capture would be into $2, etc.).