Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Regex, lo strumento del diavolo.

    Salve a tutti, ho un problemino con le espressioni regolari, tanto per cambiare.

    Allora, io un array pieno di valori tipo questo:

    e vorrei recuperare il "26 Jun 2007 19:38:35 UTC" buttando via il resto. la regex che ho scritto è la seguente:

    $regex3 = "#<a href=\"\\.\\./sched_logs/.+>(.+)</a>#";

    ma non mi prende tutti i valori.
    Sbaglio qualcosa io?

  2. #2
    http://it.php.net/manual/en/referenc....php#id6359506

    In particolare:
    By default, the quantifiers are "greedy", that is, they match as much as possible (up to the maximum number of permitted times), without causing the rest of the pattern to fail. The classic example of where this gives problems is in trying to match comments in C programs. These appear between the sequences /* and */ and within the sequence, individual * and / characters may appear. An attempt to match C comments by applying the pattern /\*.*\*/ to the string /* first comment */ not comment /* second comment */ fails, because it matches the entire string due to the greediness of the .* item.

    However, if a quantifier is followed by a question mark, then it ceases to be greedy, and instead matches the minimum number of times possible, so the pattern /\*.*?\*/ does the right thing with the C comments. The meaning of the various quantifiers is not otherwise changed, just the preferred number of matches. Do not confuse this use of question mark with its use as a quantifier in its own right. Because it has two uses, it can sometimes appear doubled, as in \d??\d which matches one digit by preference, but can match two if that is the only way the rest of the pattern matches.
    Addio Aldo, amico mio... [03/12/70 - 16/08/03]

  3. #3
    Grazie della risposta
    Effettivamente mi ero chiesto come si comportassero le regex in casi 'ambigui'...


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.