Gedit regular expressions plugin: Difference between revisions

From WickyWiki
Line 13: Line 13:


== Examples ==
== Examples ==
Note: use the example strings without the quotes.


=== Replace trailing whitespaces and /r with /n ===
=== Replace trailing whitespaces and /r with /n ===


Search:  
Search:  
  '[ \t\r\n]{1,9}'
  [ \t\r\n]{1,9}
 
Replace with:  
Replace with:  
  '\n'
  \n


=== Split word with capital letter in the middle ===
=== Split word with capital letter in the middle ===


Search:
Search:
  '([a-z,.])([A-Z])'
  ([a-z,.])([A-Z])


Replace with:
Replace with:
  '\1 \2'
  \1 \2


=== Search 1 (one) in a non-number ===
=== Search 1 (one) in a non-number ===


Search:
Search:
  '[^0-9]1[^0-9]'
  [^0-9]1[^0-9]


=== Search number > 9 ===
=== Search number > 9 ===
Line 44: Line 43:


Search:
Search:
  '([a-z])-\n{1,9}([a-z])'
  ([a-z])-\n{1,9}([a-z])


Replace with:
Replace with:
  '\1\2'
  \1\2


=== Remove EOL: trailing and leading non-capital letter ===
=== Remove EOL: trailing and leading non-capital letter ===


Search:
Search:
  '([a-z,;:])[ \n]{1,9}([a-z])'
  ([a-z,;:])[ \n]{1,9}([a-z])


Replace with:
Replace with:
  '\1 \2'
  \1 \2


=== Remove EOL: leading non-capital letter ===
=== Remove EOL: leading non-capital letter ===


Search:
Search:
  '\n{1,9}([a-z])'
  \n{1,9}([a-z])


Replace with:
Replace with ('_' should be a space):
  ' \1'
  _\1


=== Remove EOL: trailing non-capital letter===
=== Remove EOL: trailing non-capital letter===
([a-z,;:])\n{1,9}
 
\1
Search:
([a-z,;:])\n{1,9}
 
Replace with ('_' should be a space):
\1_


== Regular expressions in Office Libre ==
== Regular expressions in Office Libre ==

Revision as of 18:20, 16 November 2011

Install

  1. download the plugin from http://halfhourhacks.blogspot.com/2008/03/gedit-regular-expression-plugin.html
  2. extract the contents to ~/.gnome2/gedit/plugins/ you will have these files:
    • ~/.gnome2/gedit/plugins/regex_replace.gedit-plugin
    • ~/.gnome2/gedit/plugins/regex_replace.gedit-plugin/regex_replace
  3. restart gedit
  4. in the menu: Edit -> Preferences -> plugins -> enable Expression Replace
  5. now you should have a "Regular Expression" item in the Search menu.

Other gedit plugins

Examples

Replace trailing whitespaces and /r with /n

Search:

[ \t\r\n]{1,9}

Replace with:

\n

Split word with capital letter in the middle

Search:

([a-z,.])([A-Z])

Replace with:

\1 \2

Search 1 (one) in a non-number

Search:

[^0-9]1[^0-9]

Search number > 9

Search:

'[0-9]{2,3}\n{2,3}'

Remove '-' in words

Search:

([a-z])-\n{1,9}([a-z])

Replace with:

\1\2

Remove EOL: trailing and leading non-capital letter

Search:

([a-z,;:])[ \n]{1,9}([a-z])

Replace with:

\1 \2

Remove EOL: leading non-capital letter

Search:

\n{1,9}([a-z])

Replace with ('_' should be a space):

_\1

Remove EOL: trailing non-capital letter

Search:

([a-z,;:])\n{1,9}

Replace with ('_' should be a space):

\1_

Regular expressions in Office Libre

You can also use regular expressions in Office Libre.

Remove paragraph trailing space

Search:

'^(.*) $'

Replace with:

'$1'