Main Menu

Regular Expression Repository

Started by Stefan, December 04, 2008, 10:19:17 PM

Previous topic - Next topic

Stefan

Delete all (i.e. one or more) leading space and tabs:

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

Replace
$2
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

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)
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

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)
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

JJK

Very nice post. I encourage you to give us your other tricks.

alex

#4
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 :)
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

Stefan

#5
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.
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

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 [ ]:      \[((\\")|[^"(\\")])+\]

-

Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Arthur

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?

alex

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...
HippoEDIT team
[url="http://www.hippoedit.com/"]http://www.hippoedit.com/[/url]

Stefan

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.
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Stefan

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


Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-