Regex Snippets

Sa., 21/04/2012 - 17:44
Body

Regex Libraries

http://regexlib.com/

Regex Beispiele

What it doesRegex
Select all from the Beginning ^.*
^foo "foo" at the start of a string
foo$ "foo" at the end of a string
^foo$ "foo" when it is alone on a string
[abc] a, b, or c
[a-z] Any lowercase letter
[^A-Z] Any character that is not a uppercase letter
(gif|jpg) Matches either "gif" or "jpeg"
[a-z]+ One or more lowercase letters
[0-9\.\-] Аny number, dot, or minus sign
^[a-zA-Z0-9_]{1,}$ Any word of at least one letter, number or _
([wx])([yz]) wy, wz, xy, or xz
[^A-Za-z0-9] Any symbol (not a number or a letter)
([A-Z]{3}|[0-9]{4}) Matches three letters or four numbers

Zeilenanfang mit Zeilennummer löschen

Folgender regulärer Ausdruck
  1. ^.*[0-9]+\.
  2. ^.*[0-9]+\.\R
(zweiter Eintrag mit Zeilenumbruch) entfernt
  1.    4.
  2. oder
  3.    14.

Meta Character

Metacharacters sind nicht innerhalb von Klassen aktiv. Beispiel: [akm$] Dieses Beispiel "matched" jeden der Buchstaben "a", "k", "m", or "$"; "$". Doch "$" ist ein Metacharacter der innerhalb eine Klasse nicht als einfaches Zeichen erkannt wird (er hat normalerweise eine Spezialfunktion) Nicht matchen [^5] "Match" jedes Zeichen außer 5. \d Findet alle Dezimalzeichen und ist gleich mit [0-9] \D Findet alle nicht Zahlen Zeichen und ist gleich mit [^0-9] \s Findet Leerzeichen und ist gleich mit [ \t\n\r\f\v] \S Findet alle Zeichen außer Leerzeichen und ist gleich mit [^ \t\n\r\f\v] \w Findet alle alphanumerischen Zeichen (Buchstaben+Zahlen) und ist gleich mit [a-zA-Z0-9_] \W Findet alle nicht alphanumerischen Zeichen gleich mit [^a-zA-Z0-9_] Man kann diese innerhalb einer Klasse nutzen z.B. [\s,.] Findet alle Leerzeichen oder Kommas oder Punkte. grep -rnzoP '(?s)\?>\s+?\Z' matcht alle dateien mit leerzeichen oder umbrüchen nach closing tags Suche BOM grep -rl $'\xEF\xBB\xBF' . Suche nach BOM in *.module dateien fgrep -i $'\xEF\xBB\xBF' `find . -iname '*.module' -print`
Webdevelopment
Add new comment
The content of this field is kept private and will not be shown publicly.

Plain text

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <drupal-entity data-*>
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.