Difference between revisions of "User:Hegen/Test"

From Apache OpenOffice Wiki
Jump to: navigation, search
(dont use categories on test pages)
Line 627: Line 627:
 
}}
 
}}
  
 +
<nowiki>
 
[[Category:Documentation/Reference]]
 
[[Category:Documentation/Reference]]
 
[[Category:Writer]]
 
[[Category:Writer]]
 
[[Category:Documentation/How Tos/Writer]]
 
[[Category:Documentation/How Tos/Writer]]
 +
</nowiki>

Revision as of 11:13, 11 November 2009


Introduction

Einführung

In simple terms, regular expressions are a clever way to find & replace text (similar to 'wildcards'). Regular expressions can be both powerful and complex, and it is easy for inexperienced users to make mistakes. We describe the use of OpenOffice.org regular expressions aiming to be clear enough for the novice, while detailing the aspects that can cause confusion to more experienced users. In einfachen Worten, Reguläre Ausdrücke (RegEx für Regular Expressions HJS) sind ein intelligenter Weg um Text zu suchen oder zu ersetzen (vergleichbar zu 'Joker'-Zeichen). Reguläre Ausdrücke können sowohl mächtig als auch kompliziert sein. Das macht es für unerfahrene Nutzer leicht fehleranfällig. Wir wollen die Nutzung von OpenOffice.org – Regulären Ausdrücken einerseits so hilfreich darstellen, dass es für einen Neuling klar genug ist und andererseits die Aspekte detailliert darstellen die erfahrenere Nutzer irritieren können.

A typical use for regular expressions is in finding text in a Writer document; for instance to locate all occurrences of man or woman in your document, you could search using a regular expression which would find both words. Eine typische Anwendung für RegEx ist das Finden von Text in einem Writer-Dokument; z.B. um alle Vorkommen von „man“ oder „woman“ in ihrem Dokument zu finden, kann man einen RegEx anwenden der beide Worte findet.

Regular expressions are very common in some areas of computing, and are often known as regex or regexp. Not all regex are the same - so reading the relevant manual is sensible. RegEx werden in verschiedenen Bereichen der Datenverarbeitung häufig angewendet, und werden daher oft als regex oder regexp abgekürzt. Aber nicht alle regex sind gleichartig – daher muss man die entsprechende Anleitung (Manual) genau lesen.

Where regular expressions may be used in OOo

Wo Reguläre Ausdrücke im OOo genutzt werden

In Writer: Im Writer-Modul:

  • Edit - Find & Replace dialog
  • Bearbeiten – Suchen & Ersetzen
  • Edit - Changes - Accept/reject command (Filter tab)
  • Bearbeiten – Änderungen – Akzeptieren oder Verwerfen (Tabulator Filter)

In Calc: Im Calc-Modul:

  • Edit - Find & Replace dialog
  • Bearbeiten – Suchen & Ersetzen
  • Data - Filter - Standard filter & Advanced filter
  • Daten – Filter – Standardfilter & Spezialfilter
  • Certain functions, such as SUMIF, LOOKUP
  • in einigen Funktionen, y.B. SUMWENN (sumif), SVERWEIS (lookup)

In Base:

  • Find Record command
  • Suche Datensatz

The dialogs that appear when you use the above commands generally have an option to use regular expressions (which is off by default). For example Die Dialoge beim Aufruf dieser Funktionen haben immer eine Option RegEx zu nutzen (ist aber als Standardwert ausgeschaltet). Zu Beispiel:

location of regular expression tick box
Position des Auwahlschalters für Reguläre Ausdrücke

You should check the status of the regular expression option each time you bring up the dialog, as it defaults to 'off'. Man sollte den Status dieser Option jedes mal beim Aufruf des Dialogs kontrollieren, da er standardmäßig ausgeschaltet ist.

A simple example

Ein einfaches Beispiel

If you have little or no experience of regular expressions, you may find it easiest to study them in Writer rather than say Calc. Wenn man wenig oder gar keiner Erfahrung von RegEx hat, wird man es am einfachsten finden sie im Writer-Modul zu erproben anstelle sagen wir im Calc-Modul.

In Writer, bring up the Find and Replace dialog from the Edit menu. Im Writer rufen wir den „Suchen & Ersetzen“ Dialog aus dem Bearbeiten Menue auf.

On the dialog, choose More Options and tick the Regular Expressions box Im Dialog, wählen wir „Mehr Optionen“ und klicken die „Regulären Ausdrücke“-Box an.

In the Search box enter r.d - the dot here means 'any single character'. In die Suchbox tragen wir „r.d“ ein – der Punkt bedeutet hier 'jedes einzelne Zeichen'.

Clicking the Find All button will now find all the places where an r is followed by another character followed by a d, for instance 'red' or 'hotrod' or 'bride' or 'your dog' (this last example is r followed by a space followed by d - the space is a character). Wenn man jetzt den Suche alles Knopf betätigt, werden alle Stellen an denen ein r gefolgt von einem anderen Zeichen, gefolgt von einem d auftaucht gefunden, z.B. red oder 'hotrod' oder 'bride' oder 'your dog' (im letzten Beispiel wird r gefolgt von einem Leerzeichen (space) gefolgt von einem d gefunden – der Abstand (Leerzeichen) ist ein Zeichen).

If you type xxx into the Replace with box, and click the Replace All button, these become 'xxx', 'hotxxx', 'bxxxe', 'youxxxog' Gibt man xxx in die Ersetzen mit Box ein, und betätigt man den Ersetzen alles Knopf, so bekommt man 'xxx', 'hotxxx', 'bxxxe', 'youxxxog' .

That may not be very useful, but it shows the principle. We'll continue to use the Find and Replace dialog to explain in more detail. Das mag nicht sehr sinnvoll erscheinen, aber es demonstriert das Prinzip. Wir werden den Suchen und Ersetzen Dialog im Weiteren genauer erklären.

The least you need to know about regular expressions

Das Mindeste was sie über Reguläre Ausdrücke wissen müssen

If you don't want to find out exactly how regular expressions work, but just want to get a job done, you might find these common examples useful. Enter them in the 'Search for' box, and make sure that regular expressions are selected. Wenn Sie nicht genau wissen wollen wie RegEx normalerweise arbeiten, aber ihre Aufgabe erfüllt heben wollen, werden sie diese allgemeinen Beispiele nützlich finden. Geben sie sie in das 'Suche nach'-Feld ein, und sorgen sie dafür das die RexEx-Option eingeschaltet ist.

  • color|colour finds color and colour
  • sep.rate finds sep then any character then rate - eg separate, seperate, and indeed sepXrate
  • sep[ae]rate finds separate and seperate - [ae] means either an a or an e
  • changed? finds change and changed - the d is optional because it is followed by a question mark
  • s\> finds the s at the end of a word
  • \<. finds the first letter of a word.
  • ^. finds the first letter of a paragraph.
  • ^$ finds an empty paragraph
  • color|colourfindet color und colour (beide Wörter richtig)
  • sep.rate findet sep dann ein beliebiges Zeichen rate - so separate, seperate, und wirklich auch sepXrate
  • sep[ae]rate findet separate und seperate - [ae] bedeutet entweder ein a oder ein e
  • changed? findet change und changed - das d ist optional weil es von einem Fragezeichen gefolgt wird
  • s\> findet das s am Ende des Wortes
  • \<. findet den ersten Buchstaben eines Wortes.
  • ^. findet den ersten Buchstaben eines Absatzes
  • ^$ findet einen leeren Absatz

How regular expressions are applied in OpenOffice.org

Wie Reguläre Ausdrücke in OOo angewendet werden

OpenOffice.org regular expressions appear to divide the text to be searched into portions and examine each portion separately. OOo RegEx scheinen den zu durchsuchenden Text in Portionen aufzuteilen und jede einzelne Portion separat zu Untersuchen.

In Writer, text appears to be divided into paragraphs. For example x.*z will not match x at the end of a paragraph with z beginning the next paragraph ( x.*z means x then any or no characters then z). Paragraphs seem to be treated separately (although we discuss some special cases at the end of this HowTo). Im Writer-Modul tritt Text in Absätze geteilt auf. Z.B. x.*z entspricht nicht einem x am Ende eines Absatzes dessen nächster Absatz mit einem z beginnt (x.*z bedeutet ein x dann irgend ein oder gar kein Zeichen dann z).Absätze werden also seperat untersucht (obwohl wir am Ende dieser Handreichung (HowTo) einige spezielle Fälle diskutieren werden).

the scope of regular expressions
the scope of regular expressions

In addition Writer considers each table cell and each text frame separately. Text frames are examined after all the other text / table cells on all pages have been examined. Zusätzlich betrachtet Writer jede Tabellenzelle und jedes Frame separat. Text Frames (Textrahmen) werden nach allen anderen Text oder Tabellenzellen untersucht.

In the Find & Replace dialog, regular expressions may be used in the Search for box. In general they may not be used in the Replace with box. The exceptions are discussed later. Im Suchen & Ersetzen Dialog werden RegEx im Suchen nach Feld eingesetzt. Normalerweise werden sie nicht im Ersetzen Feld verwendet.. Die Ausnahmen werden später dargestellt.

Literal characters

Buchstaben/Literale

If your regular expression contains characters other than the so-called 'special characters' . ^ $ * + ? \ [ ( { | then those characters are matched literally. Wenn im RegEx Zeichen enthalten sind die keine sogenannten 'Sonderzeichen' . ^ $ * + ? \ [ ( { | sind, so werden sie als Buchstaben (bzw. Literale) bezeichnet.

For example: red matches red redraw and Freddie. Zum Beispiel: red entspricht red redraw und Freddie.

OpenOffice.org allows you to choose whether you care if a character is 'UPPER CASE' or 'lower case'. If you tick the box to 'match case' on the Find and Replace dialog, then red will not match Red or FRED; if you un-tick that box then the case is ignored and both will be matched. OOo erlaubt es zwischen der Unterscheidung von GROßBUCHSTABEN (UPPER CASE) und kleinbuchstaben (lower case) oder ihrem Ignorieren zu wählen. Wenn man die Box 'Groß-/Kleinschreibung' im Suchen & Ersetzen-Dialog anwählt, entspricht red nicht RED oder F'RED; anderfalls wird die Schreibweise ignoriert und beide werden gefunden.


Special characters

Sonderzeichen

The special characters are . ^ $ * + ? \ [ ( { | Die Sonderzeichen sind . ^ $ * + ? \ [ ( { |

They have special meanings in a regular expression, as we're about to describe. Sie haben besondere Bedeutungen in RegEx, die wir beschreiben werden.

If you wish to match one of these characters literally, place a backslash '\' before it. Braucht man eines dieser Zeichen in seiner eigenen Zeichenfunktion, wird ein Backslash '\' (umgedrehter Schrägstrich) vor das Zeichen gesetzt.

For example: to match $100 use \$100 - the \$ is taken to mean $ . Zum Beispiel: für die Suche nach $100 nutzt man \$100 – das \$ nimmt man für $ .

Single character match .  ?

Einzelzeichensuche mit . oder ?

The dot '.' special character stands for any single character (except newline). Das Punkt .' Sonderzeichen steht für jedes einzelne Zeichen (außer Zeilenvorschub).


For example: r.d matches 'red' and 'hotrod' and 'bride' and 'your dog' Zum Beispiel: r.d entspricht 'red' und 'hotrod' und 'bride' und 'your dog'

The question mark '?' special character means 'match zero or one of the preceding character' - or 'match the preceding character if it is found'. Das Fragezeichen '?' steht für 'keines oder genau dem Zeichen dem es folgt' bzw. 'zeige das vorangegangene Zeichen wenn es vorhanden ist'.


For example: rea?d matches 'red' and 'read' - 'a?' means 'match a single a if there is one'. Zum Beispiel: rea?d entspricht 'red' und 'read' - 'a?' heißt 'etspreche einem einzelnen Zeichen a soweit eins vorhanden ist'.


Special characters can be used in combination with each other. A dot followed by a question mark means 'match zero or one of any single chacter'. Sonderzeichen können in Kombination miteinander angewendet werden. Ein Punkt mit einem folgenden Fragezeichen heißt 'Vorkommen eines einzelnen Zeichens soweit eins da ist'.


For example: star.?ing matches 'staring', 'starring', 'starting', and 'starling', but not 'startling' Zum Beispiel: star.?ing entspricht 'staring', 'starring', 'starting', und 'starling', aber nicht 'startling'

Repeating match + * {m,n}

Wiederholtes Finden mit + * {m,n}

The plus '+' special character means 'match one or more of the preceding character'. Das Sonderzeichen Plus '+' bedeutet 'Vorkommen eines oder mehrerer der vorangestellten Zeichens'.

For example: re+d matches 'red' and 'reed' and 'reeeeed' - e+ means match one or more e's. Zum Beispiel: re+d entspricht 'red' und 'reed' und 'reeeeed' - e+ heißt ein oder mehrere e's.

The star '*' special character means 'match zero or more of the preceding character'. Das Sonderzeichen Stern '*' heißt 'entspreche keinem oder mehreren des vorangegangenen Zeichens'.


For example: rea*d matches 'red' and 'read' and 'reaaaaaaad' - 'a*' means match zero or more a's . Zum Beispiel: rea*d entspricht 'red' und 'read' und 'reaaaaaaad' - 'a*' bedeutet kein oder mehrmaliges Vorkommen von a's .

A common use for '*' is after the dot character - ie '.*' which means 'any or no characters'. Eine übliche verwendung für '*' ist nach dem Punkt-Zeichen – d.h. '.*' bedeutet 'jedes oder kein Zeichen'.

For example: rea.*d matches 'read' and 'reaXd' and 'reaYYYYd' but not - 'red' or 'reXd' Zum Beispiel: rea.*d entspricht 'read' und 'reaXd' und 'reaYYYYd' aber nicht - 'red' oder 'reXd'

Use the star '*' with caution; it will grab everything it can: Benutze den Stern '*' mit Vorsicht, es findet (und verwendet) alles was möglich ist.

For example: 'r.*d' matches 'red' but in Writer if your paragraph is actually 'The referee showed him the red card again' the match found is 'referee showed him the red card' - that is, the first 'r' and the last possible 'd'. Regular expressions are greedy by nature. Zum Beispiel: 'r.*d' findet 'red' aber wenn der Absatz im Writer 'The referee showed him the red card again' umfasst, ist das Gefundene 'referee showed him the red card' - d.h. Das erste 'r' und das letzt mögliche 'd'. Reguläre Ausdrücke sind ihrer Natur nach gierig.

--- S.6

You may specify how many times you wish the match to be repeated, with curly brackets { }. For example a{1,4}rgh! will match argh!, aargh!, aaargh! and aaaargh! - in other words between 1 and 4 a's then rgh!. Man kann mit geschweiften Klammern { } angeben wie oft der Treffer wiederholt werden soll. Z.B. a{1,4}rgh! wird argh!, aargh!, aaargh! und aaaargh! finden – mit anderen Worten gesagt zwischen 1 und 4 a's gefolgt von rgh!

Also note that a{3}rgh! will match precisely 3 a's, ie aaargh!, and a{2,}rgh! (with a comma) will match at least 2 a's, for example aargh! and aaaaaaaargh!. Beachte auch das a{3}rgh! genau 3 a's finden, d.h. aaargh!, und a{2,}rgh! (mit einem Komma) entsprechen mindestens 2 a's, z.B- aargh! und aaaaaaaargh!.

Positional match ^ $ \< \>

Positionssuche ^ $ \< \>

The circumflex '^' special character means 'match at the beginning of the text'. Das Zirkumflex (oder auch Dach-)Sonderzeichen '^' bedeutet 'Finden am Textanfang'.

The dollar '$' special character means 'match at the end of the text'. Das Dollar-Zeichen '$'bedeutet 'Finden am Ende des Textes'.


Remember that OpenOffice.org regular expressions divide up the text to be searched - each paragraph in Writer is examined separately. Man erinnere sich, dass OOo RegEx den untersuchten Text unterteilt – jeder Absatz wird gesonders betrachtet.


For example: ^red matches 'red' at the start of a paragraph (red night shepherd's delight). „Z.B.:“ ^red entspricht 'red' am Anfang des Absatzes (red night shepherd's delight).

For example: red$ matches 'red' at the end of a paragraph (he felt himself go red) „Z.B.:“ red$ entspricht 'red' am Ende des Absatzes (he felt himself go red).

For example: ^red$ matches inside a table cell that contains just 'red' „Z.B.:“^red$ entspricht dem Inhalt einer Zelle die nur 'red' enthält.

In addition a hard line break (entered by Shift-Enter) is considered the beginning / end of text, and will allow a ^ or $ match. Zusätzlich dazu wird ein Harter Zeilenwechsel (durch Umschalt-Enter eingegeben) als Anfang oder Ende eines Textes angesehen und durch ^ oder $ gefunden.

The backslash '\' special character gives special meaning to the character pairs '\<' and '\>', namely 'match at the beginning of a word', and 'match at the end of a word' Das Backslash-Zeichen '\' hat in Kombinationen von '\<' und '\>' besondere Funktionen, insbesondere 'Finde am Wortanfang' und 'Finde am Wortende'.


For example: \<red matches red at the beginning of a word (she went redder than he did). „Z.B.:“\<red entspricht red am Wortanfang (she went redder than he did).

For example: red\> matches red at the end of a word (although neither of them cared much.) „Z.B.:“red\> entspricht red am Wortende (although neither of them cared much.)


The test used to define the beginning/end of a word seems to be that the previous/next character is a space, underscore (_), tab, newline, paragraph mark or any non-alphanumeric character. Das Charakteristikum um den Worbeginn/Wortende zu bestimmen ist das das voangegangene bzw. folgende Zeichen ein Leerzeichen, ein Unterstreichungsstrich (_), ein Tabulator, ein Zeilenwechsel, ein Absatz oder irgendein nicht-alphanumerisches Zeichen ist.


For example: \<red matches 'person@rediton.com' „Z.B.:“\<red entspricht 'person@rediton.com'

For example: red\> matches 'I said, "No-one dared" ' „Z.B.:“red\> entspricht 'I said, "No-one dared" '

Alternative matches | [...]

Alternatives Vorkommen | [...]

The pipe character '|' is a special character which allows the expression either side of the '|' to match. Das Pipe-Zeichen (senkrechter Strich) '|' ist ein Sonderzeichen das den Ausdruck auf der einen oder anderen Seite vom '|' als Treffer erkennt.


For example: red|blue matches 'red' and 'blue' „Z.B.:“red|blue entspricht 'red' und 'blue'

Unfortunately, certain expressions when used after a pipe are not evaluated. This is so far known to affect ^ and backreferences, and is the subject of issue 46165 Leider werden manche Ausdrücke die nach einer Pipe stehen nicht ausgewertet. Das betrifft soweit bekannt ^ und rückwirkende Bezüge. Das ist auch der Inhalt der Fehlermeldung issue 46165


For example: ^red|blue matches paragraphs beginning with 'red' and any occurrence of 'blue', but blue|^red incorrectly matches only any occurrence of 'blue', failing to match paragraphs beginning with 'red' „Z.B.:“^red|blue entspricht Absätzen beginnend mit 'red' und jedes Vorkommen von 'blue', aber blue|^red entspricht unkorrekterweise nur jedem Vorkommen von 'blue', und findet Absätze die mit 'red' beginnen nicht.


The open square brackets character [ is a special character. Characters enclosed in square brackets are treated as alternatives - any one of them may match. You can also include ranges of characters, such as a-z or 0-9, rather than typing in abcdefghijklmnopqrstuvwxyz or 0123456789 Die eckigen Klammern [ sind besondere Sonderzeichen. Zeichen die durch Eckige Klammern eingeschlossen werden werden als Alternativen bewertet – jedes von ihnen erfüllt die Suche.Man kann sowohl Reihen von Zeichen wie a-z und 0-9 oder jedes einzelne Zeichen wie abcdefghijklmnopqrstuvwxyz oder 0123456789 eingeben.


For example: r[eo]d matches 'red' and 'rod' but not 'rid' „Z.B.:“r[eo]d entspricht 'red' und 'rod' aber nicht 'rid'

For example: [m-p]ut matches 'mut' and 'nut' and 'out' and 'put' „Z.B.:“[m-p]ut entspricht 'mut' und 'nut' und 'out' und 'put'

For example: [hm-p]ut matches 'hut' and 'mut' and 'nut' and 'out' and 'put' „Z.B.:“[hm-p]ut entspricht 'hut' und 'mut' und 'nut' und 'out' und 'put'


Special characters within alternative match square brackets do not have the same special meanings. The only characters which do have special meanings are ], -, ^ and \, and the meanings are: Sonderzeichen in eckige Klammern eingeschlossen haben nicht die entsprechenden abweichenden Bedeutungen. Die einzigen Zeichen mit besonderer Bedeutung sind ], -, ^ and \. Deren Bedeutung ist dann:

  • ] - a closing square bracket ends the alternative match set [abcdef]
  • ] - die schließende eckige Klammer beendet die alternative Zeichenmenge [abcdef]


  • ^ - if the caret is the first character in the square brackets, it negates the search. For example [^a-dxyz] matches any character except abcdxyz.
  • ^ - Ist das Karet (Dach) das erste Zeichen zwischen den eckigen Klammern negiert es die Suche. „Z.B.:“ [^a-dxyz] entspricht allen Zeichen außer abcdxyz.
  • \ - the backslash is used to allow ], -, ^ and \ to be used literally in square brackets, and to allow hexadecimal codes.
  • \ - der Backslash erlaubt den Sonderzeichen ], -, ^ and \ in ihrer eigentlichen Form genutzt zu werden, oder hexadezimale Codes einzugeben.

For example, \] stands for a literal closing square bracket, so [[\]a] will match an opening square bracket [, a closing square bracket ] or an a. \\ stands for a literal backslash. \x0009 stands for a tab character. „Z.B.:“\] steht für eine Zeichenkette mit einer schließenden eckigen Klammer, wie [[\]a] für eine öffnende eckige Klammer [, eine schließende eckige Klammer ] oder ein a steht. \x0009 steht für ein Tabulator-Zeichen.

Just to re-emphasise: these are the meanings of these characters inside square brackets, and any other characters are treated literally. For example [\t ] will match a 't' or a space - not a tab or a space. Use [\x0009 ] to match a tab or a space. Noch mal zur Rekapitulation: das sind die Bedeutungen dieser Zeichen innerhalb von eckigen Klammern, viele andere Zeichen werden direkt gefunden. „Z.B.:“[\t ] entspricht 't' oder einem Leerzeichen - nicht einem Tabulator oder einem Leerzeichen. Für einen Tabulator oder Leerzeichen nutzt man [\x0009 ].

--- S.7

POSIX bracket expressions [:alpha:] [:digit:] etc..

POSIX Klammerausdrücke [:alpha:] [:digit:] usw.

There is much confusion in the OpenOffice.org community about these. The Help itself is also far from clear.

Es gibt eine ganze Menge Irritation darüber in der OpenOffice.org community. Sogar die Help-Dokumentation ist unklar formuliert.


There are a number of 'POSIX bracket expressions' (sometimes called 'POSIX character classes') available in OpenOffice.org regular expressions, of the form [:classname:] which allow a match with any of the characters in that class. For instance [:digit:] stands for any of the digits 0123456789.

Es gibt eine Reihe von `POSIX Klammerausdrücken' (manchmal als 'POSIX Zeichenklasse' bezeichnet) die in Ooo RegEx verfügbar sind in der Form [:classname:], die es erlauben irgend ein Zeicchen diesr Klasse zu finden. Z.B. [:digit:] entspricht irgend einem Zeichen von 0123456789.


These (by definition) may only appear inside the square brackets of an alternative match - so a valid syntax would be [abc[:digit:]], which should match a, b, c, or any digit 0-9. A correct syntax to match just any one digit would be [[:digit:]].

Per Definition dürfen sie nur innerhalb der eckigen Klammern einer alternativen Suche auftreten – würde eine gültige Syntax [abc[:digit:]] sein, die a, b, c, oder jede Zahl 0-9 finden sollte. Eine korrekte Syntax für jede Zahl wäre [[:digit:]].


Unfortunately this does not work as it should! The correct syntax does not work at all, but currently an incorrect syntax ([:digit:]) will actually match a digit, as long as it is outside the square brackets of an alternative match. (Obviously this is unsatisfactory, and is the subject of issue 64368).

Leider funktioniert das nicht so wie es sollte! Die korrekte Sytax funtioniert überhaupt nicht, aber derzeit findet die Falsche Darstellung ([:digit:]) eine Zahl wenn sie sich außerhalb der eckigen Klammern einer alternativ Suche befindet. („Natürlich ist das unbefriedigend und wird in der Fehlermeldung issue 64368 behandelt).


The POSIX bracket expressions available are listed below. Note that the exact definition of each depends on locale - for example in a different language other characters may be considered 'alphabetic letters' in [:alpha:]. The meanings given here apply generally to English-speaking locales (and do not take into account any Unicode issues).

Die POSIX-Klammerausdrücke die zur Verfügung stehen sind untewn aufgelistet. Man Beachte, das die exakte Definition von der „Lokalisierung“ abhängt – z.B. In einer anderen Sprache andere 'Buchstaben' in [:alpha:] erwartet werden können. Die hier aufgeführten Bedeutungen gellten für englische Muttersprachler (und nehmen keinen Bezug auf Unicode Ausführungen).


[:digit:] 
stands for any of the digits 0123456789. This is equivalent to 0-9.
[:digit:] 
steht für jede Zahl 0123456789. Das entspricht 0-9.


[:space:] 
should stand for any whitespace character, including tab; however as currently implemented it stands simply for a space character. Note that the Help is currently misleading here. (This is the subject of issue 41706).
[:space:] 
sollte für jedes whitespace Zeichen (Abstands-Zeichen Leer,Tab,usw.) stehen, obwohl es eigentlich nur das Leerzeichen darstellt. Man Beachte, das die Hilfe hier in die Irre führt. (Gegenstand der Fehlermeldung issue 41706).


[:print:] 
should stand for any printable character; however as currently implemented it does not match the single quote nor the double quote characters ‘ ’ “ ” (and some others such as « »). It matches space, but does not match tab (this latter is expected/defined behaviour). (This is the subject of issue 83290).
[:print:] 
sollte für jeder druckbare Zeichen stehen, trotzdem findet es derzeit nicht die (einfachen oder doppelten) Anführungsstriche ‘ ’ “ ” (und einige andere wie « »). Es findet Leerzeichen aber keine Tabulatorzeichen (das ist späterer erwarteter /definierter Inhalt). (Fehlermeldung: issue 83290).


[:cntrl:] 
steht für ein Steuerzeichen. Soweit es Nutzer betrifft, hat OOo sehr wenige Steuerzeichen, Tabulator und harter Zeilenumbruch werden beide gefunden, die Absatzmarke jedoch nicht.


[:alpha:] 
stands for a letter (including a letter with an accent). For example in the phrase (often used in English, and here given with accents as in the original language) 'déjà vu' all 6 letters will match.
[:alpha:] 
stehen für einen Buchstaben (einschließlich Buchstaben mit Akzent). Z.B. in der Phrase 'déjà vu' (die im Englischen öfters verwendet wird und hier mit den Akzenten der Originalsprache geschrieben ist) werden alle 6 Buchstaben gefunden.


[:alnum:] 
stands for a character that satisfies either [:alpha:] or [:digit:]
[:alnum:] 
steht für Zeichen die entweder [:alpha:] oder [:digit:] sind.


[:lower:] 
stands for a lowercase letter (including a letter with an accent). The case matching does not work unless the Match case box is ticked; if this box is not ticked this expression is equivalent to [:alpha:].
[:upper:] 
stands for an uppercase letter (including a letter with an accent). The case matching does not work unless the Match case box is ticked; if this box is not ticked this expression is equivalent to [:alpha:].
[:upper:] 
steht für Großbuchstaben (einschließlich Buchstaben mit Akzent). Die Großschreibungs- Unterscheidung funktioniert nur wenn die Groß/Kleischreibung sbox markiert ist, ansonsten entspricht die Wirkung [:alpha:].


There seems to be little consistency in any implementation of POSIX bracket expressions (OOo or elsewhere). One approach is simply to use straightforward character classes - so instead of [[:digit:]] you use [0-9] for example.

Es erscheint etwas unsystematisch in jeder Implementation von POSIX Klammerausdrücken zu stecken )OOo oder sonstwo). Eine Herangehensweise ist einfach die direkten Zeichenklassen zu verwenden – so z.B. anstelle von [[:digit:]] benutzt man [0-9].


Grouping (...) and backreferences \x $x

Gruppieren (…) und Rückbezüge \x $x

Round brackets ( ) may be used to group terms.

Runde Klammern '"( )"' können zum Gruppieren von Termen verwendet werden.


For example: red(den)? will find 'red' and 'redden'; here (den)? means 'one or zero of den'.

"Z.B.:" red(den)? wird 'red' und 'redden' finden; (den)?bedeutet 'ein oder keinmal den'.


For example: (blue|black)bird will find both 'bluebird' and 'blackbird'.

"Z.B.:" (blue|black)bird findet sowohl 'bluebird' als auch 'blackbird'.


Each group enclosed in round brackets is also defined as a reference, and can be referred to later in the same expression using a 'backreference'. In the 'Search for' box, backreferences are written '\1', '\2', etc.; in the 'Replace with' box they are written '$1', '$2', etc.

Jede Gruppe in runden Klammern ist zusätzlich als Bezug definiert, und kann später im selben Ausdruck als 'Rückbezug' verwendet werden. In der 'Suche nach' Box werden Rückbezüge als '\1', '\2', etc. und in der 'Ersetzen durch' Box als '$1', '$2' usw.


'\1' or '$1' stands for 'whatever matched in the first round brackets'; '\2' or '$2' stands for 'whatever matched in the second round brackets'; and so on.

'\1' oder '$1' steht für 'irgend etwas das zwischen den ersten runden Klammern stand'; '\2' or '$2' für 'irgend etwas das zwischen den zweiten runden Klammern stand' usw.


For example: (blue|black) \1bird in the 'Search for' box will find both 'blue bluebird' and 'black blackbird', because '\1' stands for either blue or black, whichever we found. Therefore 'black bluebird' does not match.

"Z.B." (blue|black) \1bird in der 'Suchen' Box wird sowohl 'blue bluebird' als auch 'black blackbird' finden, weil '\1' entweder für "blue" oder "black" steht, wasimmer auch gefunden wurde. Darum wird auch 'black bluebird' nicht gefunden.


Backreferences in the 'Replace with' box only work from OOo2.4 onwards. The use of $1 rather than \1 is consistent with perl syntax, and more particularly with the ICU regex engine, which may at some time replace the existing OOo regex engine, thus resolving many issues.

'"Rückbezüge in der 'Erstzen durch' Bax funktionieren erst ab OOo2.4 aufwärts'". Die Nutzung von §1 anstelle von \1 hängt mit der Perl-Syntax zusammen, teilweise auch mit der ICU-Reguläre Ausdrücke-Engine (Bearbeitungsfunktion) , die in manchen Fällen die übliche Ooo-Bearbeitungsfunktion für reguläre Ausdrücke ersetzt, was zu vielen Fehler führen kann.


For example: (gr..n)(blu.) in the 'Search for' box will find 'greenblue'; if the 'Replace with' box has $2$1 the replacement will be 'bluegreen'.

"Z.B.:" (gr..n)(blu.) in der Suchfunktion findet 'greenblue'; in der Erstezungsfunktion erzeugt $2$1 'bluegreen'.


When regular expressions are selected, to replace text with the literal character '$' you must now use '\$'; similarly for '\' use '\\'.

Wenn die Regulären Ausdrücke zur Textersetzung von '$' verwendet werden, muss man dann mit '\$' entsprechend für '\' bei '\\' arbeiten.


For example: (1..) in the 'Search for' box and \$$1 in the 'Replace with' box replaces '100' with '$100', and '150' with '$150'.

Z.B.: im 'Suchen nach' Feld und \$$1 im 'Ersetzen durch' ersetzt '100' durch '$100', und '150' durch '$150'.


$0 in the 'Replace with' box replaces with the entire text found.

$0 im 'Ersetzen durch' Feld überschreibt mit dem gesamten gefundenen Text.


Tabs, newlines, paragraphs \t \n $

Tabulatoren, Zeile, Absatzmarke \t \n $

The character pair '\t' has special meaning - it stands for a tab character.

Das Zeichenpaar '\t' hat eine besondere Bedeutung – es steht für das tab (Tabulatorzeichen).


For example: \tred will match a tab character followed by the word 'red'.

Z.B.: \tred findet ein tab Zeichen gefolgt vom Wort 'red'.


In Writer a newline may be entered by pressing Shift-Enter. A newline character is thereby inserted into the text, and the following text starts on a new line. This is not the same as a new paragraph; click View-Non printing characters to see the difference.

Im Writer kann ein Zeilenwechsel durch Umschalt-Eingabe ( Shift-Enter) eingegeben werden. Dabei wirt ein Zeilenumbruch-Zeichen in den Text eingefügt, und der folgende Text beginnt auf einer neuen Zeile. Das ist nicht das gleiche wie ein neuer Absatz. Klickt man "Steuerzeichen anzeigen" an sieht man den Unterschied.


The OOo regular expression behaviour when matching paragraph marks and newline characters is 'unusual'. This is partly because regular expressions in other software usually deal with ordinary plain text, whereas OOo regular expressions divide the text at paragraph marks. For whatever reason, this is what you can do:

Das Ooo RegEx Verhalten ist für Absatzmarken und Zeilenumbruch-Zeichen etwas 'ungewöhnlich'. Das kommt zum Teil davon , dass in anderen Programmen RegEx auf normalen Text angewendet wird, wo hingegen Ooo RegEx den Text an Absatzmarken unterteilt. Was auch immer der Grund ist, das kann man machen:


  • \n will match a newline (Shift-Enter) if it is entered in the Search box. In this context it is simply treated like a character, and can be replaced by say a space, or nothing. The regular expression red\n will match red followed by a newline character - and if replaced simply by say blue the newline will also be replaced. The regular expression red$ will match 'red' when it is followed by a newline. In this case, replacing with 'blue' will only replace 'red' - and will leave the newline intact.
  • red\ngreen will match 'red' followed by a newline followed by 'green'; replacing with say 'brown' will remove the newline. However neither red.green nor red.*green will match here - the dot . does not match newline.
  • $ on its own will match a paragraph mark - and can be replaced by say a 'space', or indeed nothing, in order to merge two paragraphs together. Note that red$ will match 'red' at the end of a paragraph, and if you replace it with say a space, you simply get a space where 'red' was - and the paragraphs are unaffected - the paragraph mark is not replaced. It may help to regard $ on its own as a special syntax, unique to OOo.
  • ^$ will match an empty paragraph, which can be replaced by say nothing, in order to remove the empty paragraph. Note that ^red$ matches a paragraph with only 'red' in it - replacing this with nothing leaves an empty paragraph - the paragraph marks at either end are not replaced. It may help to regard ^$ on its own as a special syntax, unique to OOo. Unfortunately, because OOo has taken over this syntax, it seems you cannot use ^$ to find empty cells in a table (nor empty Calc cells).
  • If you wish to replace every newline with a paragraph mark, firstly you will search for \n with Find All to select the newlines. Then in the Replace box you enter \n, which in the Replace box stands for a paragraph mark; then choose Replace. This is somewhat bizarre, but at least now you know. Note that \r is interpreted as a literal 'r', not a carriage return.
  • \n entspricht einenem Zeilenwechsel(Shift-Enter) im 'Suchen nach' Feld. In diesem Zusammenhang wird es nur als ein einfaches Zeichen behandelt, und kann durch Beispielsweise ein Leerzeichen (Space) oder garnicht ersetzt werden. Der RegEx-Ausdruck red\n entspricht red gefolgt von einem Zeilenwechsel-Zeichen - und wenn es nur durch blue ersetzt wird, wird der Zeilenumbruch mit ersetzt.Der RegEx-Ausdruck red$ entspricht 'red' wenn es von einem Zeilenumbruch gefolgt wird. In diesem Fall führt das Ersetzen durch'blue' nur zum Ersetzen von 'red' - dasbei wirde der Zeilenwechsel nicht verändert (bleibt intakt).
  • red\ngreen entspricht 'red' gefolgt von einem Zeilenumbruch gefolgt von 'green'; ein Ersetzen durch 'brown' entfernt den Zeilenumbruch.Jedenfalls weder red.green noch red.*green werden hier fündig – der Punkt . findet keinen Zeilenwechsel.
  • $ slebst entspricht der Absatzmarke -und kann z.B. mit Leerzeichen 'space' ersetzt werden oder entfernt werden, um zwei Absätze zu Vereinigen. Beachte: red$ entspricht 'red' am Absatzende, und wenn man es mit Beispielsweise einem Leerzeichen space ersetzt, erhält man nur ein Leerzeichen space wo 'red' war -und der Absatz bleibt unberührt – die Absatzmarke wird nicht ersetzt. Es kann helfen $ selbst als spezifische Syntax zu betrachten , einmalig in OOo.
  • ^$ entspricht einem leeren Absatz, der durch 'Nichts' ersetzt werden kann, wenn man den leeren Absatz entfernen will. Beachte: ^red$ entspricht einem Absatz der nur 'red' enthält – erstetzt man das mit 'Nichts' verbleibt ein leerer Absatz – die Absatzmarken an jedem Ende werden nicht ersetzt. Wie schon bekannt: Es kann helfen $ selbst als spezifische Syntax zu betrachten , einmalig in OOo. Leider kann man daher wahrscheinlich auch ^$ nicht nutzen um leere Zellen in Tabellen (oder auch im Calc ) zu finden, da diese Syntax im ganzen OOo übernommen wurde.
  • Will man jeden Zeilenwechsel mit einem Absatz ersetzen, muss man zunächst nach \n suchen mit ausgewähltem 'Finde alle' um die Zeilenwechsel zu markieren. Dann in der 'Ersetzen mit'-Zelle \n eingeben, das hier für die Absatzmarke steht, und dann Ersetzen auswählen. Note that \r is interpreted as a literal 'r', not a Das ist etwas bizarr, aber zumindest jetzt wissen Sie es. Beachte: \r wird als Zeichen 'r' interpretiert nicht als Zeilenschaltung (carriage return).


To replace paragraph marks - as used to give lines a certain length in some html documents, for instance - with "normal" automatically wrapped lines and paragraphs, the following 3 steps should help.

Zur Ersetzung von Absatzmarken – wie sie Benutzt werden um Zeilen eine bestimmte Länge in html-Dokumenten zu geben, z.B. durch "normale" automatisch umgebrochene Zeilen und Absätze, sollten folgende drei Schritte helfen:

1. So as not to lose "normal" paragraph marks at the end of "normal" paragraphs, replace two consecutive paragraph marks using a sequence of characters not occurring anywhere else in the text, like "*****" to replace an empty paragraph - this makes it easy to find and reinstate later. You do this by putting ^$ in the Find box and "*****" in the Replace box. (If you're only dealing with a limited chunk of text, don't forget to check "current selection only" under "more options" in the Find and Replace box.) 1. Damit man keine "normalen" Absatzmarken am Ende "normaler" Absätze verliert, ersetze zwei aufeinander folgende Absatzmarken mit einer Zeichenfolge die sonst nicht im Text vorkommt, wie "*****" um einen leerewn Absatz zu ersetzen – das macht es später einfacher ihn wiederzufinden und zu ersetzten. Das macht man durch Eingabe von ^$ in der 'Suchen' Zelle und "*****" in die 'Ersetzen' box. (Arbeitet man mit begrenzt ausgewähltem Text, darf man nicht vergessen die "Nur in Selektion" unter "Mehr Optionen" von "Suchen und Ersetzen zu markieren)

2. Search for the remaining line-end paragraph marks by putting $ in the Find box. To replace the mark with a "space" just type a space in the Replace dialogue. 2. Man sucht nach den verbliebenen Zeilenende-Absatzmarken durch Eingabe von $ im 'Suchen' Feld. Um die Marke mit einem einfachen Leerzeichen zu Überschreiben braucht man bloß ein Leerzeichen im 'Ersetzen durch' Dialog einzugeben.

3. Now that the text is ready for normal line-wrapping, put back the "normal" paragraph marks by typing "*****" in the Find box and \n in the Replace box. (Remember to check "current selection only" where appropriate!) 3. Jeztzt ist der Text breit für das Rückumwandeln des normalen Zeilenumbruchs durch Eingabe von "*****" in der 'Suchen' box und \n in der 'Ersetzen mit' box. (Beachte das Überprüfen von "Nur in Selektion" falls sie ausgewählt wurde.)


Before you try this, create a test document to practise on.

Vor dem erstmaligen Einsatz dieser Befehlsfolge, sollte man es an einem Testdokument geübt haben.


This is a good sequence to make into a macro.

Für diese Befehlsfolge bietet sich ein Macro an.


It also helps deal indirectly with line-break problems.

Sie hilft auch indierekt bei Zeilenumbruchsproblemen.


Hexadecimal codes \xXXXX

Hexadezimal Codes \xXXXX

The character sequence ' \x then a 4 digit hexadecimal number ' stands for the character with that code.

Die Zeichenfolge ' \xvierstellige Hexadezimal-Zahl' entspricht dem Zeichen mit diesem Code.


For example: \x002A stands for the star character '*'.

Z.B.: \x002A steht für das Stern-Zeichen '*'.


Hexadecimal codes can be seen on the 'Insert-Special Character' dialog.

Die Hexadezimal-Codes sieht man beim "Einfügen-Sonderzeichen" Dialog.


The 'Replace with' box \t \n & $1 $2

Die 'Ersetzen mit' Box \t \n & $1 $2

Users are sometimes confused with what can be done using the 'Replace with' box in a Find & Replace dialog.

Nutzer sind manchmal verunsichert, was man alles mit der 'Ersetzen mit' Box im 'Suchen und Ersetzen' Dialog machen kann.


In general, regular expressions do not work in the 'Replace with' box. The characters you type replace the found text literally.

Im allgemeinen "funktionieren" RegEx in der 'Ersetzen durch' Box nicht. Eingebene Zeichen ersetzen dengefundenen Text Buchstabengetreu.


The four constructs that do work are:

Die vier folgenden Konstrucktionen funktionieren jedoch:


  • \t inserts a tab, replacing the text found.
  • \n inserts a paragraph mark, replacing the text found. This may be unexpected, because \n in the 'Search for' box means 'newline'! In some operating systems it is possible to use unicode input to directly type a newline character (U+000A) in the 'Replace with' box, providing a workaround, but this is not universal.
  • $1, $2, etc are backreferences, which (from OOo2.4) insert text groups found. See under Grouping and backreferences. $0 inserts the entire text found.
  • & also inserts the entire text found.
  • \t fügt ein Tabulatorzeichen ein, das den gefundenen Text überschreibt.
  • \n fügt eine Absatzmarke ein, die den gefundenen Text überschreibt. Das kann unbeabsichtigt sein, weil \n in der 'Suchen nach' Box 'Zeilenwechsel' bedeutet! In einigen Betriebssystemen kann man Unicode direkt in die 'Ersetzen' Box einfügen und hat damit einen anderen Weg um das Zeilenwechsel Zeichen (U+000A) einzugeben. Das gilt aber nicht überall.
  • $1, $2, usw. sind Rückbezüge (seit Ooo2.4) die gefundene Text-Gruppen einfügen können. Mehr dazu unter Grouping and backreferences. $0 fügt den gesamten gefundenen Text ein.
  • & fügt ebenfalls den gesamten gefundenen Text ein.


For example if you searched for bird|berry, you would would find either 'bird' or 'berry'; now to replace with black& would give you either 'blackbird' or 'blackberry'.

Z.B. sucht man nach bird|berry, findet man entweder 'bird' oder 'berry', ersetzt man mit black& erhält man entweder 'blackbird' oder 'blackberry'.


Troubleshooting OOo regular expressions

Fehlersuche bei OOo RegEx

If you are new to regular expressions, please realise that they can be tricky - if you are not getting the results you expect, you might need to check that you understand well enough. Try to keep regular expressions as simple and unambitious as possible.

Ist man noch nicht mit RegEx vertraut, muss man Beachten dass sie kompliziert sein können – wenn man nicht das erwartete Ergebnis erhält, muss man überprüfen ob man sie ausreichend verstanden hat. Man sollte Versuchen RexEx so einfach und bescheiden wie möglich einzusetzten.

Here are some further points of interest with OOo regular expressions:

Hier sind weitere interessante Aspekte von OOo RegEx.


  • If you find an unexpected behaviour, please check in the relevant section in this HowTo - many of the behaviour issues have been documented here.
  • Regular expressions are 'greedy' - that is they will match as much text as they can. Consider using curly and square brackets; for example [^ ]{1,5}\> matches 1 to 5 non-space characters at the end of a word.
  • Please be careful when using the Replace All button. There are a few rare occasions when this will give unexpected results. For example to remove the first character of every paragraph you might 'Search for' ^. and 'Replace with' nothing; clicking 'Replace All' now will wipe out *all* your text, instead of just the first character of each paragraph. Issue 82473 discusses this. The workaround is to 'Find All', then 'Replace'; perhaps the safest way is not to use the 'Replace All' button at all with regular expressions.
  • Findet man ein unerwartetes Verhalten vor, sollte man die betreffende Sektion dieser Anleitung (HowTo) noch mal betrachten – viele Verhaltensprobleme sind hier dokumentiert.
  • RegEx Ausdrücke sind 'gierig' ('greedy') – d.h. Sie finden so viel Text wie möglich. Daher sollte man geschweifte und eckige Klammern nutzen; Z.B.:' [^ ]{1,5}\> entspricht 1 bis 5 nichtleeren Zeichen am Ende eines Wortes.
  • Besonders Vorsichtig sollte man den "Ersetze alles" Knopf benutzen. Es gibt eine Reihe von sehr seltenen Fällen in denen sehr unerwartete Resultate auftreten. Z.B. Um das erste Zeichen eines jeden Absatzes zu entfernen könnte man nach ^. Suchen und beim 'Ersetzen mit' 'Nichts' eintragen; 'Ersetze alles' wird nun den gesamten Text löschen, anstelle nur des ersten Zeichens jedes Absatzes. Die Fehlermeldung Issue 82473 stellt das datr. Eine Lösung ist 'Suche alle'dann 'Ersetzen'; aber der sicherste Weg ist 'Ersetze alle' in RegEx zu vermeiden.


Tips and Tricks

Tips and Tricks

Here are some examples that may be useful:

Hier sind noch einige nützliche Beispiele.

\<([^ ]+)[ ]+\1

finds duplicate words separated by spaces (note that there is a space before each ])
findet Wortdoppelungen die durch Leerzeichen getrennt sind (Beachte da ist ein Leerzeichen vor jedem ])

\<[:alpha:]*\>

finds any word in the whole document (notice:the check box regular expression must by checkt)


\<[1-9][0-9]*\>

finds decimal numbers
findet Dezimalzahlen


\<0[0-7]*\>

finds octal (base 8) numbers
Findet Oktalzahlen (Basis 8)


\<0x[A-Fa-f0-9]+\>

finds hexadecimal (base 16) numbers
findet Hexadezimalzahlen (Basis 16)


[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-z]{2,6}

finds most email addresses (there is no perfect regular expression - this is a practical solution)
findet die Mehrzahl von E-Mail Adressen (kein perfekter RegEx – aber eine Praxislösung)


Template:Documentation/SeeAlso

[[Category:Documentation/Reference]] [[Category:Writer]] [[Category:Documentation/How Tos/Writer]]

Personal tools
In other languages