Gedit regular expressions plugin: Difference between revisions

From WickyWiki
No edit summary
Line 18: Line 18:
=== Replace /r/n with /n ===
=== Replace /r/n with /n ===


{|style="color:navy; background-color:#ffffcc;" cellpadding="5" cellspacing="0" border="1"
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400
! width=50% | Search !! Replace with
|-
|-
! Search
| \r\n || \n
! Replace with
|-
| \r\n
| \n
|}
|}


Check:
Check:


{|style="color:navy; background-color:#ffffcc;" cellpadding="5" cellspacing="0" border="1"
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400
|-
! Search
! Search
|-
|-
| \r
| \r  
|}
|}


=== Remove trailing white-spaces ===
=== Remove trailing white-spaces ===


{|style="color:navy; background-color:#ffffcc;" cellpadding="5" cellspacing="0" border="1"
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400
|-
! width=50% | Search !! Replace with
! Search
! Replace with
|-
|-
| [ \t]{1,9}\n
| [ \t]{1,9}\n || \n
| \n
|}
|}


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


{|style="color:navy; background-color:#ffffcc;" cellpadding="5" cellspacing="0" border="1"
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400
|-
! width=50% | Search !! Replace with
! Search
! Replace with
|-
|-
| ([a-z,.])([A-Z])
| ([a-z,.])([A-Z])
Line 60: Line 51:
=== Replace 1 (one) in a non-number with I ===
=== Replace 1 (one) in a non-number with I ===


{|style="color:navy; background-color:#ffffcc;" cellpadding="5" cellspacing="0" border="1"
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400
! width=50% | Search !! Replace with
|-
|-
! Search
| [^0-9]1[^0-9] || I
! Replace with
|-
| [^0-9]1[^0-9]  
| I
|}
|}


=== Search number > 9 ===
=== Search number > 9 ===


{|style="color:navy; background-color:#ffffcc;" cellpadding="5" cellspacing="0" border="1"
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400
|-
! width=50% | Search
! Search
|-
|-
| [0-9]{2,9}
| [0-9]{2,9}
Line 80: Line 67:
=== Remove hyphenation '-' from words ===
=== Remove hyphenation '-' from words ===


{|style="color:navy; background-color:#ffffcc;" cellpadding="5" cellspacing="0" border="1"
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400
|-
! width=50% | Search !! Replace with
! Search
! Replace with
|-
|-
| ([a-z])-\n{1,9}([a-z])
| ([a-z])-\n{1,9}([a-z]) || \1\2
| \1\2
|}
|}


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


{|style="color:navy; background-color:#ffffcc;" cellpadding="5" cellspacing="0" border="1"
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400
|-
! width=50% | Search !! Replace with
! Search
! Replace with
|-
|-
| ([a-z,;:])\n{1,9}([a-z])
| ([a-z,;:])\n{1,9}([a-z]) || \1 \2
| \1 \2
|}
|}


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


{|style="color:navy; background-color:#ffffcc;" cellpadding="5" cellspacing="0" border="1"
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400
! width=50% | Search !! Replace with
|-
|-
! Search
| \n{1,9}([a-z]) || _\1
! Replace with
|-
| \n{1,9}([a-z])
| _\1
|}
|}


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


{|style="color:navy; background-color:#ffffcc;" cellpadding="5" cellspacing="0" border="1"
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400
! width=50% | Search !! Replace with
|-
|-
! Search
| ([a-z,;:])\n{1,9} || \1_
! Replace with
|-
| ([a-z,;:])\n{1,9}
| \1_
|}
|}


Line 128: Line 103:
=== Remove paragraph trailing spaces ===
=== Remove paragraph trailing spaces ===


{|style="color:navy; background-color:#ffffcc;" cellpadding="5" cellspacing="0" border="1"
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400
|-
! width=50% | Search !! Replace with
! Search
! Replace with
|-
|-
| ^(.*) {1,9}$
| ^(.*) {1,9}$ || $1
| $1
|}
|}

Revision as of 20:48, 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

Note: where needed an underscore (_) is used to denote a space.

Replace /r/n with /n

Search Replace with
\r\n \n

Check:

Search
\r

Remove trailing white-spaces

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

Split word with capital letter in the middle

Search Replace with
([a-z,.])([A-Z]) \1 \2

Replace 1 (one) in a non-number with I

Search Replace with
[^0-9]1[^0-9] I

Search number > 9

Search
[0-9]{2,9}

Remove hyphenation '-' from words

Search Replace with
([a-z])-\n{1,9}([a-z]) \1\2

Remove EOL: trailing and leading non-capital letter

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

Remove EOL: leading non-capital letter

Search Replace with
\n{1,9}([a-z]) _\1

Remove EOL: trailing non-capital letter

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

Regular expressions in Office Libre

You can also use regular expressions in Office Libre. Note that variables are noted with a '$'.

Remove paragraph trailing spaces

Search Replace with
^(.*) {1,9}$ $1