perl regular expressions
Dave Wilson
dw at botanicus-badspam.net
Wed Jul 10 07:09:41 CDT 2002
Hi people.
Technically I'm not a perl user, but I have been abusing PHP's PCRE module
quite a lot recently, so I thought this question was suitable here.
I have this little beauty:
/%([#0\-+'I]?)([\-0-9]*)(\.[0-9\*m\$]*)?([hlLqjzt])
?([diouxXeEfFgGaAcsCSpn])/";
Which will match (my interpretation of) any valid glibc2.2 ..printf format
specifier (according to the man page). This is going to be used for
modifying a format string before it reachs ..printf. It breaks the
specifier down like so:
[Dave %-4.21ls was here ]
Array
(
[0] => %-4.21ls
[1] => -
[2] => 4
[3] => .21
[4] => l
[5] => s
)
Viewing <a.php>
Now for my problem.. I have a function (which currently isn't using regexs)
which takes an input line like "%20s %.10S %5s %B", and associated arguments
for the specifiers. It modifies the format string to be "%20s %.10s %5s %u",
at the same time as doing some magic on the argument associated with the
%S and %B specifiers (there are others too).
My problem with doing this using a PCRE is finding out the exact position
in the format string where the 'S' of "%...S" occured. Is there a fancy way
in perl regexs to get the regex parser to drop its current offset into a
register?
If not, I can just strlen each component part and work it out that (ugly)
way. Thanks in advance..
Dave
More information about the Belfast-pm
mailing list