
kaza_perl
New User
Jun 8, 2013, 8:46 PM
Post #4 of 6
(22196 views)
|
Re: [Laurent_R] How to match a function of back reference?
[In reply to]
|
Can't Post
|
|
Thanks for everyone who replied! The whole /match/ regex is a part of already written script so it places a limitation of single-line regex. I hoped that there is some (strange?) syntax allowing matching a function of a back reference, in a similar way to a replacement by a function of a match, like: @{[${1}-1]} but as I see from the replies, there isn't such a thing. OK, either I'll have to use groups of 4 or 8 regex arguments (for indices [1-4]->[0-3], [1-8]->[0-7], they're not diverse) instead of a single regex argument I hoped to come with or I'll have to declare in the script a hardcoded associative array
%q_dec = { '1','0', '2','1', '3','2', '4','3', '5','4', '6','5', '7','6', '8','7', }; and match values of it pointed by a back reference. BTW, if the whole match regex is used like:
if ($line_of_text =~ m/${regex}/) {... can the $regex itself contain reference like:
^\w+_([1-8])_\w+_${q_dec{\1}}_\w+ ? I attempted it, it didn't match, I attempted even declaring a simple constant and attempting to match only the "0" value like by having the regex include:
^\w+_([1-8])_\w+_${a_const}_\w+ but it still didn't match. Am I overlooking something with the syntax? TIA,
|