Using Padre's Regex Editor today, very nice tool. I thought I might be able to split a pattern on a string of the same character, but that didn't seem to want to play. I could use something like unpack, but wondered if there were any tricks to doing this using split?
my @splitted = split /(?:(?=a{2})(?<=a{2}))/, 'aaaaaaaaa'; print join " ", @splitted; output recieved :aa a a a a a aa output desired :aa aa aa aa a
The main issue is that at each position there is a match, so the string is split at every position. I tried a mix of assertions and literals but the best I got was to match two at the start and end with single entities in between
I have a solution with s/// that I am happy about. I'm getting a count and any remainders modulo the length of the test string remain in the string. If I need to I can write a while loop rather than a map, though this is probably already better for what I want.
my $prim_to_test = ${ num_to_nat(2) }[0]; #get_wildmarks(); 'aa' my $split_pattern = qr/(\Q$prim_to_test\E)/; print "split_pat: $split_pattern\n"; my @splitted = map "$_ x $1", ( $wildmarks =~ s/(?=$split_pattern)$split_pattern//g ); print "splitted: ", join " \N{U+68} ", @splitted, "r: $wildmarks"; output:splitted: 4 x aa h r: a
But can split do it?
SPoiler ALert: Yes.
Further, it would appear the ability to use arbitrary characters is also expanded
In reply to Can split split against more than one character in a string of the same character? by Don Coyote
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |