in reply to Re: Re: special regexp
in thread special regexp

Aha!

Let's keep trying it regex-less.

If you need just any second character, you could use substr:

my $str='xjxexrxoxexnxexsxxx'; my $idx = -1; my $str_2nd = ''; $str_2nd .= substr( $str, $idx+=2, 1) while( $idx < length $str); print "\n$str_2nd\n";
You can achieve the same with split:
my $str='xjxexrxoxexnxexsxxx'; my @chars = split //, $str; my @chars_2nd; while ( scalar @chars ){ shift @chars; push @chars_2nd, shift @chars; } print join '', @chars_2nd;

Is this more like it? Just note that these solutions don't know what each other character ('x') is. It gets trickier if you allow more than one character between each delimiter 'x'.

Jeroen
"We are not alone"(FZ)

Replies are listed 'Best First'.
Re: Re: Re: Re: special regexp
by jorg (Friar) on Mar 26, 2001 at 14:02 UTC
    Your first solution breaks with the string 'xnox' (which should not produce any output as there are no characters residing between two x'es), it just displays 'nx' which is undesired. Your second solution suffers from the same problem.
    Whenever there are alternating x's and other chars (even x's as well) your solution is perfect, however it does not take into account that their can be multiple chars between x's. (mind you the original post did not mention this either but it's not unrealistic to assume this)

    Jorg

    "Do or do not, there is no try" -- Yoda
      Well, I already mentioned this in my post (last line). There is no easy way to solve this, as I said. How would one now if 'xtxaxix' would mean taxi or tai?

      Jeroen
      "We are not alone"(FZ)