Gedit regular expressions plugin: Difference between revisions
From WickyWiki
No edit summary |
|||
| Line 50: | Line 50: | ||
=== Replace \r\n with \n === | === Replace \r\n with \n === | ||
Unix style end-of-line. | |||
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | {|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | ||
! | ! Search | ||
|- | |- | ||
| \r | | \r | ||
|} | |} | ||
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | {|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | ||
! Search | ! width=50% | Search !! Replace with | ||
|- | |- | ||
| \r | | \r\n || \n | ||
|} | |} | ||
| Line 73: | Line 73: | ||
|} | |} | ||
=== | === Remove EOL: trailing and leading non-capital letter === | ||
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | {|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | ||
! width=50% | Search !! Replace with | ! width=50% | Search !! Replace with | ||
|- | |- | ||
| ([a-z, | | ([a-z,;:])\n{1,9}([a-z]) || \1 \2 | ||
| \1 \2 | |||
|} | |} | ||
=== | === Remove EOL: leading non-capital letter === | ||
Note: an underscore (_) is used here to signify a space. | |||
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | {|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | ||
! width=50% | Search !! Replace with | ! width=50% | Search !! Replace with | ||
|- | |- | ||
| | | \n{1,9}([a-z]) || _\1 | ||
|} | |} | ||
=== | === Remove EOL: trailing non-capital letter=== | ||
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | {|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | ||
! width=50% | Search | ! width=50% | Search !! Replace with | ||
|- | |- | ||
| [ | | ([a-z,;:])\n{1,9} || \1_ | ||
|} | |} | ||
| Line 106: | Line 107: | ||
|} | |} | ||
=== Remove | === Remove paragraph trailing spaces === | ||
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | {|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | ||
! width=50% | Search !! Replace with | ! width=50% | Search !! Replace with | ||
|- | |- | ||
| ( | | ^(.*) {1,9}$ || $1 | ||
|} | |} | ||
=== | === Split word with capital letter in the middle === | ||
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | {|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | ||
! width=50% | Search !! Replace with | ! width=50% | Search !! Replace with | ||
|- | |- | ||
| | | ([a-z,.])([A-Z]) | ||
| \1 \2 | |||
|} | |} | ||
=== | === Replace 1 (one) in a non-number with I === | ||
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | {|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | ||
! width=50% | Search !! Replace with | ! width=50% | Search !! Replace with | ||
|- | |- | ||
| | | [^0-9]1[^0-9] || I | ||
|} | |} | ||
== | === Search number > 9 === | ||
{|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | {|style="text-align:center;background-color:#ffffdd;" cellpadding=5 cellspacing=0 border=1 width=400 | ||
! width=50% | Search | ! width=50% | Search | ||
|- | |- | ||
| | | [0-9]{2,9} | ||
|} | |} | ||
== Regular expressions in Office Libre == | |||
You can also use regular expressions in Office Libre. Note that variables are noted with a '$'. | |||
Revision as of 14:48, 9 December 2012
Install
- download the cortrect plugin from https://bitbucket.org/brandizzi/gedit-re-search/wiki/Home
- extract the contents to gedit plugin directory, typically:
- ~/.gnome2/gedit/plugins (gedit2)
- ~/.local/share/gedit/plugins (gedit3)
- restart gedit
- in the menu: Edit -> Preferences -> plugins -> enable 'RegEx Search and Replace'
- now you should have a 'Regular Expression..' -item in the Search menu.
Other gedit plugins
Some regular expressions
| Expression | Matches |
|---|---|
| \t | tab |
| \r | carriage return (CR) |
| \n | newline (LF) |
| . | any character |
| [1234abcd] | any of the specified characters |
| [^1234abcd] | none of the specified characters |
| [0-9a-zA-Z] | any of the characters within the specified ranges |
| expr* | 'expr' repeats 0 to multiple times |
| expr+ | 'expr' repeats 1 to multiple times |
| expr{n,m} | 'expr' repeats n to m times |
| (expr) | use 'expr' in the replacement with \1 \2 \3 etc |
| ^ | start of line |
| $ | end of line |
Examples
Replace \r\n with \n
Unix style end-of-line.
| Search |
|---|
| \r |
| Search | Replace with |
|---|---|
| \r\n | \n |
Remove trailing white-spaces
| Search | Replace with |
|---|---|
| [ \t]{1,9}\n | \n |
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
Note: an underscore (_) is used here to signify a space.
| Search | Replace with |
|---|---|
| \n{1,9}([a-z]) | _\1 |
Remove EOL: trailing non-capital letter
| Search | Replace with |
|---|---|
| ([a-z,;:])\n{1,9} | \1_ |
Remove hyphenation '-' from words
| Search | Replace with |
|---|---|
| ([a-z])-\n{1,9}([a-z]) | \1\2 |
Remove paragraph trailing spaces
| Search | Replace with |
|---|---|
| ^(.*) {1,9}$ | $1 |
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} |
Regular expressions in Office Libre
You can also use regular expressions in Office Libre. Note that variables are noted with a '$'.