SGMLXML.net A place for SGML and XML application developers.

March 11, 2005

SED Replacement Command

Filed under: REGEXP — cangione @ 2:32 pm




sed -i 's/[reg expr that is]/[replacement]/g' [file(s)]

Find all entities within a document

Filed under: REGEXP — cangione @ 2:32 pm




&[^;]*;

Summary of regular expressions

Filed under: REGEXP — cangione @ 2:32 pm




Operator

Description

.

Any single character. Example: h.t matches hat, hit, hot and hut.

[ ]

Any one of the characters in the brackets, or any of a range of characters separated by a hyphen (-), or a character class operator (see below). Examples: h[aeiou][a-z] matches hat, hip, hit, hop, and hut; [A-Za-z] matches any single letter; x[0-9] matches x0, x1, …, x9.

[^]

Any characters except for those after the caret “^”. Example: h[^u]t matches hat, hit, and hot, but not hut.

^

The start of a line (column 1).

$

The end of a line (not the line break characters). Use this for restricting matches to characters at the end of a line. Example: end$ only matches “end” when it’s the last word on a line, and ^end only matches “end” when it’s the first word on a line.

\<

The start of a word.

\>

The end of a word.

\t

The tab character.

\xdd

dd” is the two-digit hexadecimal code for any character.

\( \)

Groups a tagged expression to use in replacement expressions. An RE can have up to 9 tagged expressions, numbered according to their order in the RE. The corresponding replacement expression is \x, for x in the range 1-9. Example: If \([a-z]+\) \([a-z]+\) matches “way wrong”, \2 \1 would replace it with “wrong way”.

*

Matches zero or more of the preceding characters or expressions. Example: ho*p matches hp, hop and hoop.

?

Matches zero or one of the preceding characters or expressions. Example: ho?p matches hp, and hop, but not hoop.

+

Matches one or more of the preceding characters or expressions. Example: ho+p matches hop, and hoop, but not hp.

\{count\}

Matches the specified number of the preceding characters or expressions. Example: ho\{2\}p matches hoop, but not hop.

\{min,\}

Matches at least the specified number of the preceding characters or expressions. Example: ho\{1,\}p matches hop and hoop, but not hp.

\{min,max\}

Matches between min and max of the preceding characters or expressions. Example: ho\{1,2\}p matches hop and hoop, but not hp or hooop.

\|

Matches either the expression to its left or its right. Example: hop\|hoop matches hop, or hoop.

 

Remove Trailing or Preceeding White Space from an Element

Filed under: REGEXP — cangione @ 2:32 pm




Trailing White Space:
[[:space:]]*</
Preceeding White Space:
<my>[[:space:]]*

Powered by WordPress