Liste over regulære udtryk

Term

Repræsentation/brug

Hvilket som helst tegn

Det givne tegn, medmindre det er metategn i et regulært udtryk, som følger i denne tabel.

.

Ethvert enkelt tegn undtagen et linjeskift eller et afsnitskift. For eksempel matcher søgeordet "Pe.er" både "Peder" og "Peter".

^

Begyndelsen at et afsnit eller en celle. Specielle objekter såsom tomme felter eller tegn-forankrede rammer i begyndelsen af et afsnit ignoreres. Eksempel: "^Peter" matcher kun ordet "Peter", når det er det første ord i et afsnit.

$

Slutningen af et afsnitsnit eller en celle. Specielle objekter såsom tomme felter eller tegn-forankrede ramme i slutninge af et afsnit ignoreres. Eksempel: "Peter$" matcher kun ordet "Peter", når det er det sidste ord i et afsnit. Bemærk, at "Peter" ikke kan følges af et punktum.

$ alene svarer til slutningen på et afsnit. På denne måde er det muligt af søge og erstatte afsnitsskilletegn.

*

Ingen eller flere af de regulære udstryk umiddelbart foran. For eksempel matcher "Ab*c" både "Ac", "Abc", "Abbc", "Abbbc" og så videre.

+

Et eller flere af de regulære udtryk middelbart foran. For eksempel finder "AX.+4" "AXx4", men ikke "AX4".

Den længst mulige streng, som matcher dette regulære udtryk i et afsnit, matches altid. Hvis afsnittet indeholder strengen "AX 4 AX4", fremhæves hele passagen.

?

Ingen eller et af de regulære udtryk umiddelbart foran. For eksempel matcher "Tekst?" både "Tekst" og "Tekster" og "x(ab|c)?y" finder "xy", "xaby" eller "xcy". Dansk

\

Det specialtegn, der følger det, fortolkes som et almindeligt tegn og ikke som metategn for et regulært udtryk (undtagen kombinationerne "\n", "\t", "\b", "\>" og "\<"). For eksempel matscher "træ\." ordet "træ.", men ikke "træer" eller "trætte".

\n

Et linjeskift, som blev indsat med tastekombinationen Skift+Enter, i tekstfeltet Find.

Et afsnitsskift, som kan indsættes med tasterne Enter eller Retur i tekstfeltet Erstat.

For at ændre linjeskift til afsnitsskift taster du \n i både Find og Erstat-felterne og udfører så en søg og erstat.

\t

Et Tabulator-tegn. Kan også bruges i Erstat-feltet.

\b

En ordgrænse. for eksempel matcher "bbog" både "bogmærke" og "bog" men ikke "kommebog", mens "bog\b" matcher både "lommebog" og "bog" men ikke "bogmærke".

Note, this form replaces the obsolete (although they still work for now) forms "\>" (match end of word) and "\<" (match start of word).

^$

Finder et tom afsnit.

^.

Finder det første tegn i et afsnit.

& eller $0

Adds the string that was found by the search criteria in the Find box to the term in the Replace box when you make a replacement.

For example, if you enter "window" in the Find box and "&frame" in the Replace box, the word "window" is replaced with "windowframe".

You can also enter an "&" in the Replace box to modify the Attributes or the Format of the string found by the search criteria.

[...]

Any single occurrence of any one of the characters that are between the brackets. For example: "[abc123]" matches the characters ‘a’, ‘b’, ’c’, ‘1’, ‘2’ and ‘3’. "[a-e]" matches single occurrences of the characters a through e, inclusive (the range must be specified with the character having the smallest Unicode code number first). "[a-eh-x]" matches any single occurrence of the characters that are in the ranges ‘a’ through ‘e’ and ‘h’ through ‘x’.

[^...]

Any single occurrence of a character, including Tab, Space and Line Break characters, that is not in the list of characters specified inclusive ranges are permitted. For example "[^a-syz]" matches all characters not in the inclusive range ‘a’ through ‘s’ or the characters ‘y’ and ‘z’.

\uXXXX

\UXXXXXXXX

The character represented by the four-digit hexadecimal Unicode code (XXXX).

The character represented by the eight-digit hexadecimal Unicode code (XXXXXXXX).

For certain symbol fonts the Unicode code for special characters may depend on the font in use. The Unicode codes can be viewed by choosing Insert - Special Character.

|

The infix operator delimiting alternatives. Matches the term preceding the "|" or the term following the "|". For example, "this|that" matches occurrences of both "this" and "that".

{N}

The post-fix repetition operator that specifies an exact number of occurrences ("N") of the regular expression term immediately preceding it must be present for a match to occur. For example, "tre{2}" matches "tree".

{N,M}

The post-fix repetition operator that specifies a range (minimum of "N" to a maximum of "M") of occurrences of the regular expression term immediately preceding it that can be present for a match to occur. For example, "tre{1,2}" marches "tre" and "tree".

{N,}

The post-fix repetition operator that specifies a range (minimum "N" to an unspecified maximum) of occurrences of the regular expression term immediately preceding it that can be present for a match to occur. (The maximum number of occurrences is limited only by the size of the document). For example, "tre{2,}" matches "tree", "treee", and "treeeee".

(...)

The grouping construct that serves three purposes.

  1. To enclose a set of ‘|’ alternatives. For example, the regular expression "b(oo|ac)k" matches both "book" and "back".

  2. To group terms in a complex expression to be operated on by the post-fix operators: "*", "+" and "?" along with the post-fix repetition operators. For example, the regular expression "a(bc)?d" matches both "ad" and "abcd" in a search.; the regular expression "M(iss){2}ippi" matches "Mississippi".

  3. To record the matched sub string inside the parentheses as a reference for later use in the Find box using the "\n" construct or in the Replace box using the "$n" construct, where the reference to the first matched sub string in the current expression in the Find box is represented by "\1" in the Find box and by "$1" in the Replace box, the reference to the second matched sub string by "\2" and "$2" respectively, and so on.

For example, the regular expression "(890)7\1\1" matches "8907890890".

With the regular expression "\b(fruit|truth)\b" in the Find box and the regular expression "$1ful" in the Replace box occurrences of the words "fruit" and "truth" can be replaced with the words "fruitful" and "truthful" respectively without affecting the words "fruitfully" and "truthfully"

[:alpha:]

Repræsenterer et bogstav (alpha er en forkortelse af det engelske ord alphabet, på dansk alfabet). Brug [.alpha:]+ for at finde et af dem.

[:digit:]

Repræsenterer et decimalciffer (digit på engelsk). Brug [:digit:]+ for at finde et af dem.

[:alnum:]

Repræsenterer et alfanumerisk tegn ([:alpha:] og [:digit:], se disse).

[:space:]

Repræsenterer et mellemrum (men ikke andre blanktegn).

[:print:]

Repræsenterer et tegn som kan udskrives (print på engelsk).

[:cntrl:]

Repræsenterer et kontroltegn ("cntrl" er en forkortelse for de engelske ord control, på dansk kontrol).

[:lower:]

Repræsenterer et lille bogstav, hvis STORE og små bogstaver er valgt i Indstillinger.

[:upper:]

Repræsenterer et stort bogstav, hvis STORE og små bogstaver er markeret i Indstillinger.


En fuldstændig liste af understøttede metakarakterer og syntaks findes på ICU Regulære udtryk dokumentation

Note that currently all named character class terms, [:alpha:] through [:upper:], must be enclosed in parentheses when used in a regular expression, see the examples that follow.

Regular expression terms can be combined to form complex and sophisticated regular expressions for searches as show in the following examples.

Eksempler

Expression

Meaning

^$

An empty paragraph.

^ specifies that the match must be at the start of a paragraph,

$ specifies that a paragraph mark or the end of a cell must follow the matched string.

^.

The first character of a paragraph.

^ specifies that the match must be at the start of a paragraph,

. specifies any single character.

e([:digit:])?

Matches "e" by itself or an "e" followed by one digit.

e specifies the character "e",

[:digit:] specifies any decimal digit,

? specifies zero or one occurrences of [:digit:].

^([:digit:])$

Matches a paragraph or cells containing exactly one digit.

^ specifies that the match must be at the start of a paragraph,

[:digit:] specifies any decimal digit,

$ specifies that a paragraph mark or the end of a cell must follow the matched string.

^[:digit:]{3}$

Matches a paragraph or cell containing only three digit numbers

^ specifies that the match must be at the start of a paragraph,

[:digit:] specifies any decimal digit,

{3} specifies that [:digit:] must occur three times,

$ specifies that a paragraph mark or the end of a cell must follow the matched string.

\bconst(itu|ruc)tion\b

Matches the words "constitution" and "construction" but not the word "constitutional."

\b specifies that the match must begin at a word boundary,

const specifies the characters "const",

( starts the group,

itu specifies the characters "itu",

| specifies the alternative,

ruc specifies the characters "ruc",

) ends the group,

tion specifies the characters "tion",

/b specifies that the match must end at a word boundary.