I am really bad in regex and my best attempt that is working from my point of view is really poor in syntax. I am sure that it can be done in a different way and shorter.
I am currently having a string that it is 24 numerical characters long and I have created a regex to split the string on pieces character by character so I can extract the odd place holders that contain the actual information that I need.
What I have so far is:
#!/usr/bin/env perl use strict; use warnings; my $sample = "041424344454647484940414"; $sample =~ /([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([ +0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])( +[0-9])([0-9])([0-9])([0-9])([0-9])([0-9])/; # 24 times the same patte +rn print "$1$3$5$7$9$11$13$15$17$19$21$23\n"; __END__ $ perl test.pl 012345678901
This is the desired output and it is working but I was wondering if there is a more elegant way to minimize replicating the same group 24 times but also being able to get the odd place holders ($1$3$5...).
I could use potentially split the string character by character and store the output in an array. Where from there I would remove the even elements and reform the array into string with join. But in my case this is not possible as the system that I am writing the regex does not support the split function or join it only supports C format commands syntax, so I am using Perl as a test tool before implementation.
If any one has any idea how to make this regex shorter feel free to drop a comment.
Thanks in advance for your time and effort, BR.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |