The stupid question is the question not asked | |
PerlMonks |
Re: Regex matching and positionby graff (Chancellor) |
on Oct 21, 2015 at 01:42 UTC ( [id://1145504]=note: print w/replies, xml ) | Need Help?? |
First, don't use non-ASCII characters in your code unless you absolutely must have them there (e.g. as a value to be assigned to a variable). As pointed out above, using non-ASCII "smart quotes" to delimit literal strings in your code is an error.
Next, if you want to use $1 ($2, etc) after doing a regex match, you have to put parens into the regex to capture some part(s) of what is being matched. Apart from those two points, there's not much that needs to be added to your code: When I run that, I get: Those offset values (6, 11, 38, 48) represent the position of the next character after the 3-letter match (where the first character of the string is at position 1). That is, "6" points to the "C" that follows the first "CAG", "11" points to the "C" that follows the next "CGG", and so on. (updated to fix a typo)
In Section
Seekers of Perl Wisdom
|
|