Sed Regular Expressions: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 6: Line 6:
=Special Characters (need to be escaped in regular expressions)=
=Special Characters (need to be escaped in regular expressions)=


<pre>
/
    /
"
    "
$ # unescaped signifies end of line  
    $ # unescaped signifies end of line  
!
    !
[
    [
]
    ]
</pre>


=Non-Special Characters (do not need to be escaped in regular expressions)=
=Non-Special Characters (do not need to be escaped in regular expressions)=

Revision as of 16:49, 5 May 2018

Internal

Special Characters (need to be escaped in regular expressions)

/
"
$ # unescaped signifies end of line 
!
[
]

Non-Special Characters (do not need to be escaped in regular expressions)

<
>
(
)
!
-
{
}

Grouping

Use \( and \) for grouping. Parentheses must be escaped to be interpreted as grouping separator.


Examples

Match everything except space:

     [^ ]*
     .*

seems to work too.

Words (digits, alpha, _):

sed -e 's/[0-9a-zA-Z_]*/THIS_WAS_A_WORD/g'

Blank spaces (spaces, tabs, newlines): \s does not seem to work.

Regular Expression Syntax

TO NORMALIZE across java Regular Expression Syntax, grep Regular Expression Syntax, sed Regular Expression Syntax.