Highlighting regular expressions in text editors

I'm starting to program, so forgive me if this is terribly obvious (which would be great news).

I do PHP development in my free time using pregmatch and recording most of my expressions with the free open source Reggex tester.

However, often I find that I just want to quickly extract something, and the only way I know it is to write my expression and then script it, which is probably funny, but welcome to my reality. :-)

What I would like is something like a simple text editor in which I can transfer my expression (given a file or buffer with embedded text) and parse this expression and return the document with the results only.

What I find is usually a regular search / replace function, as in Notepad ++, I can easily find (and replace) all instances with an expression, but I just don't know how to extract it ...

And this is probably terribly obvious, can the expression only correspond to the opposite? Then I could use something like (only the expression I'm working on now):

<a href="/browse/0/b/-dbm/a/0-0/1200000([^/]*)/0.html">([^<]*)</a> 

And replace anything that doesn't match with anything. But I am sure that this is something common and simple, I would really appreciate any pontiers.

FWIW I know grep, and I could do it using this, but I hope this is the best gui-s solution that I just don’t know about.

Thanks.

Zach


What I was hoping for would be something that would work in a more standard set of gui tools (i.e. tools that I could already use). I am grateful to all the answers, but using perl or vi or grep is what I was hoping to avoid, otherwise I would just write it myself (of course, I did), since all of them are relatively powerful low-level tools.

Perhaps I was not clear enough. As a senior system administrator, cli tools are familiar to me, I love them very much. While working at home, I find most of my time spent in gui, such as Netbeans or Notepad ++. I just think that there will be an easy way to achieve regular expression extraction using these tools (since in these cases I already used them).

Something vaguely similar to what I had in mind would be this , which will take the expression aa on the first line and url on the second line and then extract (return) the data.

It's ugly (I'll take it off after tonight because it's probably riddled with problems).

Anyway, thanks for your answers. I appreciate it.

+4
source share
7 answers

If you need a text editor with good support for regular expressions, I highly recommend Vim. Vime regex engine is quite powerful and well integrated into the editor. eg.

 :g!/regex/d 

It says to delete every line in your buffer that doesn't match the regex pattern.

 :g/regex/s/another_regex/replacement/g 

This says about every line that matches regex , do another search / replace to replace another_regex with replacement .

If you want to use the grep command line or single-line Perl / Ruby / Python / PHP for any other tool, you can filter the current buffer text with this tool and update the buffer to reflect the results:

 :%!grep regex :%!perl -nle 'print if /regex/' 
+3
source

Have you tried nregex.com?

http://www.nregex.com/nregex/default.aspx

There is a plugin for Netbeans here, but development seems to be inhibited:

http://wiki.netbeans.org/Regex

http://wiki.netbeans.org/RegularExpressionsModuleProposal

You can also try The Regulator:

http://sourceforge.net/projects/regulator/

+1
source

Most regex mechanisms allow you to match the opposite regex.

Usually with! Operator.

0
source

My suggestion is grep and cygwin if you are stuck in a windows window.

 echo "text" | grep <a href="/browse/0/b/-dbm/a/0-0/1200000([^/]*)/0.html">([^<]*)</a> 

OR

 cat filename | grep <a href="/browse/0/b/-dbm/a/0-0/1200000([^/]*)/0.html">([^<]*)</a> 
0
source

I know grep is mentioned and you don't need the cli tool, but I think ack is worth mentioning.

ack is a grep-like tool aimed at programmers with large trees heterogeneous source code.

ack is written purely in Perl, and takes advantage of Perl's regular expressions.

0
source

A good text editor can be used to perform the described actions. I use EditPadPro to find and replace functionality, and it has some other nice features, including code coloring for most major formats. The functionality of the search bar includes a regular expression mode that allows you to enter a regular expression, and then search for the first instance that identifies whether your expression matches the relevant information, and then makes it possible to replace iteratively or all instances.

http://www.editpadpro.com

0
source

What I would like is a kind of simple text editor that I can express (for a file or a buffer filled with paste text) and it parses the expression and returns the document with the results only.

You just described grep. This is exactly what grep does. What is wrong with him?

-1
source

All Articles