Sed Regular Expressions: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 54: Line 54:


=Regular Expression Syntax=
=Regular Expression Syntax=
<font color=red>TO NORMALIZE across [[Java_Regular_Expressions#Regular_Expression_Syntax|java Regular Expression Syntax]], [[Grep_Regular_Expressions#Regular_Expression_Syntax|grep Regular Expression Syntax]], [[Sed_Regular_Expressions#Regular_Expression_Syntax|sed Regular Expression Syntax]].</font>

Revision as of 23:14, 29 July 2017

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.