RegexBuddy "tradurrà" qualsiasi regex per te. Quando alimentate il vostro esempio regex, emette:
((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)
Options:^and $ match at line breaks
Match the regular expression below and capture its match into backreference number 1 «((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)»
Match the regular expression below and capture its match into backreference number 2 «(^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Note: You repeated the capturing group itself. The group will capture only the last iteration.
Put a capturing group around the repeated group to capture all iterations. «+»
Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
Match a single character present in the list below «[ \t]*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
The character “ ” « »
A tab character «\t»
Match the character “>” literally «>»
Match a single character present in the list below «[ \t]?»
Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
The character “ ” « »
A tab character «\t»
Match any single character that is not a line break character «.+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match a line feed character «\n»
Match the regular expression below and capture its match into backreference number 3 «(.+\n)*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Note: You repeated the capturing group itself. The group will capture only the last iteration.
Put a capturing group around the repeated group to capture all iterations. «*»
Match any single character that is not a line break character «.+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match a line feed character «\n»
Match a line feed character «\n*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Questo ha un aspetto piuttosto intimidatorio in forma di testo, ma è molto più leggibile in forma HTML (che non può essere riprodotto qui) o in RegexBuddy sé. Indica anche trucchi comuni (come la ripetizione di gruppi di cattura che probabilmente non sono desiderati qui).
fonte
2010-08-29 20:28:45
Forse alcuni strumenti in http://stackoverflow.com/questions/32282/regex-testing-tools aiuterà. – kennytm
Non ne faccio nessuno. Io uso sempre 6-10 linee di codice con explode/join/strstr/substr (PHP). Più facile da capire, mantenere e persino scrivere. – ern0
Non tutte le lingue o le librerie che supportano l'espressione regolare funzioneranno in modo così semplice come il tuo esempio, a causa degli spazi bianchi aggiunti. –