Author Topic: Regular Expression Repository  (Read 1890 times)

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 774
  • Karma: +6/-0
    • View Profile
Regular Expression Repository
« on: December 04, 2008, 10:19:17 pm »
Delete all (i.e. one or more) leading space and tabs:

Find
^(\s|\t)+(.+)$

Replace
$2
Stefan, HippoEDIT beta tester  (HippoEDIT News On Twitter: http://twitter.com/hippoedit/)

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 774
  • Karma: +6/-0
    • View Profile
Re: Regular Expression Repository
« Reply #1 on: December 04, 2008, 10:24:31 pm »
Replace two or more blanks (every where in the line) to one single blank

Find
\s\s+

Replace
#

(Note: instead of # insert an blank by pressing the space-bar into the Replace field)

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 774
  • Karma: +6/-0
    • View Profile
Re: Regular Expression Repository
« Reply #2 on: December 04, 2008, 11:28:19 pm »
Remove all email quoting prefixes

Find
[>\s]+

Replace


(Note: this means: Replace with nothing)

------------------------------

Reduce two or more email quoting prefixes to one single >

Find
[>\s]+

Replace
>

or Replace
>#


(Note: instead of # insert an blank after the '>'  by pressing the space-bar into the Replace field)

Offline JJK

  • Full Member
  • ***
  • Posts: 151
  • Karma: +2/-0
    • View Profile
Re: Regular Expression Repository
« Reply #3 on: December 05, 2008, 08:22:55 am »
Very nice post. I encourage you to give us your other tricks.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1712
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
Re: Regular Expression Repository
« Reply #4 on: December 05, 2008, 01:52:08 pm »
Hello Stefan,

Thanks for your help ;)

I have open for editing FAQ section, maybe you would move your topic there, I think it matches better for such advises as general section. What do you think?

Best regards,
Alex.

P.S: I have moved it :)
« Last Edit: December 05, 2008, 02:39:32 pm by alex »

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 774
  • Karma: +6/-0
    • View Profile
Re: Regular Expression Repository
« Reply #5 on: December 08, 2008, 09:23:38 pm »
This needs beta from 08.12.2008 (b550) or above
(Note: may need several runs with current beta, because RegEx match currently non-greedy)


Remove all empty lines:

Find:
(^$\r\n)+

Replace:


(Note: this means: Replace with nothing)

--------------------------------------------------------

Remove all empty lines, even if they contain space or tabs:

Find:
^\s*$\r\n

Replace:


(Note: this means: Replace with nothing)

--------------------------------------------------------

Reduce many empty lines to one single empty line:

Find:
^$\r\n(\r\n)+

Replace:
\r\n


--------------------------------------------------------

Remove lines containing "String" and don't leave empty lines back:

Find: ".+String.+\r\n"

Replace: ""


he trick here is to include the line end symbols \r\n into the search pattern.


-

This RegEx currently may need some tweaks before they works satisfied.
« Last Edit: June 29, 2010, 08:59:26 am by Stefan »

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 774
  • Karma: +6/-0
    • View Profile
Re: Regular Expression Repository
« Reply #6 on: April 27, 2009, 06:43:23 pm »
I am just remind myself on my older list.  Here is it.

I will test them with HippoEDIT and ask Alex to add them to Find&Replace Favorites as default with distribution?
Wait before use this regex till  i have removed this sentence.


find a e-mail address:       \w[-._\w]*\w.?@\w[-._\w]*\w\.\w{2,4}

find a URL:                      (mailto|news|http|ftp|https):\/\/[\w]+(\.[\w]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?

-

find hole TAGs:                <[^>]+>
find opening TAGs:           <[^/][^>]+>
find closing TAGs:            </[^>]+>
find TAGs containig XYZ:   <[^>]*\n?.*=("|')?(.*\.XYZ)("|')?.*\n?[^<]*>

-

find strings between " ":      "((\\")|[^"(\\")])+"
find strings between ( ):       \(((\\")|[^"(\\")])+\)
find strings between {}:      {((\\")|[^"(\\")])+}
find strings between [ ]:      \[((\\")|[^"(\\")])+\]

-


Offline Arthur

  • Hero Member
  • *****
  • Posts: 624
  • Karma: +1/-0
  • He who is ashamed of asking is afraid of learning.
    • View Profile
    • My Blog
Re: Regular Expression Repository
« Reply #7 on: April 27, 2009, 07:00:58 pm »
How about adding a quick help card on RegExp to the HE itself which will be also insertable into the search field, similar to the functionality popping up Syntax Help or the shortcut hints?

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1712
  • Karma: +29/-2
    • View Profile
    • HippoEDIT
Re: Regular Expression Repository
« Reply #8 on: April 27, 2009, 07:34:00 pm »
Do not know about some special popup window (I thought somewhen about some kind of intellisense foe search filed, but currently have requests with higher priority), but maybe most popular expressions, I can add into regexp menu right side of search field...

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 774
  • Karma: +6/-0
    • View Profile
Re: Regular Expression Repository
« Reply #9 on: October 06, 2009, 10:48:41 am »
Search for empty line and insert:

Find: \r\n^$
Replace: \r\nInsert this\r\n\r\nNext line

or more like a pro would do:
Find: (\r\n)^$
Replace: $1Insert this$1$1Next line


Explanation:
Find an 'empty line', \r\n
replace with 'empty line'  \r\n
AND add text "Insert text"
AND add another 'empty line'   \r\n
AND add another text "Next line"

Note:
the very last line break (not shown here but visible in HippoEDIT if View-WhiteSpace is enabled)
is inserted by HippoEDIT on its own.

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 774
  • Karma: +6/-0
    • View Profile
Re: Regular Expression Repository
« Reply #10 on: June 30, 2010, 07:58:52 am »
Search for an line which does NOT contain "string"

Find what: ^((?!string).)*$
[X] Regular Expression

Found by Alex here > http://forum.hippoedit.com/?/topic,94.msg3574.html#msg3574


Example:
^((?!Program Files\\Oracle\\Jinitiator).)*$
jumps to the first line NOT containing "Program Files\Oracle\Jinitiator" somewhere in that line,
while skipping all line containing this string.

Example 2:
For file "\HippoEDIT\data\syntax\java_spec.xml"
- open this file
- scroll down to "<Style name="Regular""
- you will see a long list of Keywords
- search for: ^((?!keyword).)*$
- you will jump over all "Keyword"-lines to "</Style>"
(Here you have could simple search for "</Style>" two,... but he, this is an example only :P



 

Related Topics

  Subject / Started by Replies Last post
6 Replies
1394 Views
Last post January 31, 2009, 10:03:18 pm
by alex
3 Replies
648 Views
Last post January 22, 2009, 03:40:27 pm
by Stefan
3 Replies
934 Views
Last post February 03, 2009, 10:08:20 pm
by Stefan
1 Replies
387 Views
Last post June 06, 2009, 03:24:43 pm
by alex
5 Replies
140 Views
Last post January 21, 2012, 06:37:41 pm
by alex