in reply to How to get Incremental charecter groups in a string

Hi Dora,

First of all, it's going to depend on exactly what you mean by incremental character string.  The word "incremental" along with your example suggests that each string starts with the next letter of the alphabet (a.. b.. c..), but then the example doesn't follow the rule.  Or do you just mean a string containing "this is <pattern> and <pattern> and <pattern> ..."?

Since the answer we give you will depend on the problem, I'd suggest you be more specific with EXACTLY what it is you're trying to match.  The answer will most likely be some kind of regular expression match, but it will depend on having a more clearly-defined question.

Also, have you tried anything yourself?  If so, show us the code you've started with ...

Update:  Looking at your question some more, think I understand what you mean by "incremental" characters.  Do you mean you want groups of characters in which each letter is further in the alphabet than the previous one?  Or do you mean (more specifically) strings where each letter is the next letter in the alphabet from the previous one?  (If it's the latter, then your example is still misleading, as bcf doesn't match.  If it's the former, then you should realize that even words like is are going to match).

Here's a possible code fragment to get you started (assuming it's the former case, where subsequent letters only need to be further in the alphabet than previous letters):

#!/usr/bin/perl -w + use strict; use warnings; + sub is_incremental { my ($word) = @_; my @letters = split //, $word; my $prev = ord(shift @letters); foreach my $letter (@letters) { my $next = ord(lc $letter); if ($next <= $prev) { return 0; } $prev = $next; } return 1; } + my $s = "This is abc and bcf and xyz and ijklmn"; + foreach my $word (split /\s+/, $s) { if (is_incremental($word)) { print "Word [$word] is 'incremental'\n"; } }

To modify this for the latter case, you could change the line "if ($next <= $prev) {" to "if ($next - $prev != 1) {".  Maybe that will help you get started.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/