Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TorgoX (1933)

TorgoX
  sburkeNO@SPAMcpan.org
http://search.cpan.org/~sburke/

"Il est beau comme la retractilité des serres des oiseaux rapaces [...] et surtout, comme la rencontre fortuite sur une table de dissection d'une machine à coudre et d'un parapluie !" -- Lautréamont

Journal of TorgoX (1933)

Sunday February 27, 2005
08:01 AM

Regexperry

[ #23407 ]
Dear Log,

Yup. I been writin JavaScript.

var haidify_re = /(([kgx])_)/ig;

function haidify (str) {  //   Turns 'ak_a' => ['span',   'a', ['u','k'], 'a' ];

  var  last_string_starts = 0,  treelet = ['span'],  i  ;

  while(1) {
    i = haidify_re.exec(str);
    if(!i) {
      if(last_string_starts != str.length)
       treelet.push( str.substr( last_string_starts ) );
      break;
    } else {
      if(last_string_starts != i.index)
       treelet.push( str.substr( last_string_starts, i.index ) );
      treelet.push( ['u', i[2] ] );
      last_string_starts = i.index + i[1].length;
    }
  }
  return treelet;
}

Interesting thing about JavaScript's RegExp system: it's pretty much a recapitulation of Perl's system, except that there's no $1 vars (instead you look in the array you get from re.exec(str)), and that the regexp cursor isn't on the string, like in Perl's pos($thing); it's instead on the RegExp object, as re.lastIndex.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.