tere: preg_match("/([0-9<>]+)/i",$i,$matches);

Hallo,

Ich bin sehr gereizt; Samstag ist einfach kein tag zum Programmieren!
immer wenns um preg_match geht, muss ich mir an den kopf greifen und würde am liebsten dachdecker werden... :-) ...nein... spaß.

also nochmal(!) wird diese funktion denn nirgend gut erklärt?

ich meine ich möchte keine 2t text wo ich morgen noch mit lesen beschftigt bin sondern kurz und prignant eine erklärung wo ich in dieser funktion was eraube und wo ich etwas ausschließe und vorallem wie ich das mache...

----------------------- reduce ---
mein problem ist eigentlich sehr simpel:
ich habe eine € - eingabe und möchte jetzt nur noch prüfen ob da auch wirklich nur ein . und zahlen drin vorkommen, falls nicht = false ist ja klar :-)
----------------------- reduce ---

auf der arbeit habe ich die funktion und jetzt bin ich daheim und aus den fingern kann ich mir nix ziehen und das archiv ist zwar voll mit sowas, aber speziell meins habe ich nicht finden können - so genug text...

ich hoffe mir antwortet noch jemand .-)

tere
THX Danke bitte gerngeschehen.

  1. Hallo,

    a) dann programmier Samstag halt nett.
    b) http://www.php.net
    c) was hast du denn schon versucht?

    Bert

    --
    E492: Not an editor command: Wq
    ln -s /dev/brain
    Klick mich or die
  2. ([0-9]+)(.)([0-9]+)

    wuerde jetzt alle positiven Betraege erlauben.

    Wenn auch negativ, dann nich ein (-) davor.
    (Ich bin nicht sicher, ob ein "-" gequoted werden muss.)

  3. Hallo tere.

    ich habe eine € - eingabe und möchte jetzt nur noch prüfen ob da auch wirklich nur ein . und zahlen drin vorkommen, falls nicht = false ist ja klar :-)

    Der simpelste RegEx, der mir einfällt: /^\d+.\d{0,2}$/. Sollte er zu simpel sein, konkretisiere dein Problem.

    Freundschaft!
    Siechfred

    --
    Nichts ist schwerer einzureißen als die Mauer in den Köpfen.
  4. Hallo tere,

    perldoc -q number:

    How do I determine whether a scalar is a number/whole/integer/float?

    Assuming that you don't care about IEEE notations like "NaN" or "Infin-
           ity", you probably just want to use a regular expression.

    if (/\D/)            { print "has nondigits\n" }
              if (/^\d+$/)         { print "is a whole number\n" }
              if (/^-?\d+$/)       { print "is an integer\n" }
              if (/[1]?\d+$/)    { print "is a +/- integer\n" }
              if (/^-?\d+.?\d*$/) { print "is a real number\n" }
              if (/^-?(?:\d+(?:.\d*)?|.\d+)$/) { print "is a decimal number\n" }
              if (/^([+-]?)(?=\d|.\d)\d*(.\d*)?(Ee)?$/)
                                   { print "a C float\n" }

    There are also some commonly used modules for the task.  Scalar::Util
           (distributed with 5.8) provides access to perl's internal function
           "looks_like_number" for determining whether a variable looks like a
           number.  Data::Types exports functions that validate data types using
           both the above and other regular expressions. Thirdly, there is "Reg-
           exp::Common" which has regular expressions to match various types of
           numbers. Those three modules are available from the CPAN.

    If you're on a POSIX system, Perl supports the "POSIX::strtod" func-
           tion.  Its semantics are somewhat cumbersome, so here's a "getnum"
           wrapper function for more convenient access.  This function takes a
           string and returns the number it found, or "undef" for input that isn't
           a C float.  The "is_numeric" function is a front end to "getnum" if you
           just want to say, ``Is this a float?''

    sub getnum {
                   use POSIX qw(strtod);
                   my $str = shift;
                   $str =~ s/^\s+//;
                   $str =~ s/\s+$//;
                   $! = 0;
                   my($num, $unparsed) = strtod($str);
                   if (($str eq '') || ($unparsed != 0) || $!) {
                       return undef;
                   } else {
                       return $num;
                   }
               }

    sub is_numeric { defined getnum($_[0]) }

    Or you could check out the String::Scanf module on the CPAN instead.
           The POSIX module (part of the standard Perl distribution) provides the
           "strtod" and "strtol" for converting strings to double and longs,
           respectively.

    Grüße,
     CK

    --
    Death is God's way of telling you not to be such a wise guy.
    http://wwwtech.de/

    1. +- ↩︎