10 sie 2010

Sprawdzenie czy string ma format godziny

Kod javascript:

function test() {
  let czas = '12:14:38';
  let re = new RegExp('([0-9]{2})\:([0-9]{2})\:([0-9]{2})','ig');
  tmp=re.exec(czas);
  if(tmp!=null) {
    let obiekt_property = '';
    for(j in tmp) obiekt_property += j + ' '+ tmp[j] + '';
    alert(obiekt_property);
  }
}

html:

<body onload="test()"></body>
26 maj 2010

Zamiana znaków za pomocą replace - różne sposoby

JavaScript

var cat ='3,4,6,9';
alert(cat.replace(RegExp(",","g"), '_'));
alert(cat.replace(",",'_','g'));
alert(cat.replace(/,/g, '_'));

W IE7(wykonano test), działa troche inaczej niż w FF. Drugie alert zwraca inny wynik.

---------------------------
Windows Internet Explorer
---------------------------
3_4_6_9
---------------------------
OK
---------------------------

---------------------------
Windows Internet Explorer
---------------------------
3_4,6,9
---------------------------
OK
---------------------------

---------------------------
Windows Internet Explorer
---------------------------
3_4_6_9
---------------------------
OK
---------------------------

30 mar 2010

Zamiana tekstów w perlu

#!/usr/bin/perl
#use strict;
#use warnings;

print "Hello, World...";
$content = '<link rel="stylesheet" href="/zabytki,2,,,,informacje.html">';

$string = $content;
$string =~ s/\<link rel=\"stylesheet\" href=\"([^\"]+)\">/http:\/\/www.wolakorybutowa.pl$1/;
print $string;
30 mar 2010

Wyrażenie regularne w perlu

#!/usr/bin/perl
#use strict;
#use warnings;

print "Hello, World...";
$content = '<link rel="stylesheet" href="/pogoda.091005.css">';

if($content =~ /^\<link rel=\"stylesheet\" href=\"\/(.+)\"/) {
    $styl_link = $1;
 print $styl_link;
}