2

Is their any wizards or tools to create and test regular expressions for PHP, because it is so difficult :( ? thanks :)

Jan Goyvaerts
  • 21,379
  • 7
  • 60
  • 72
ahmed
  • 14,316
  • 30
  • 94
  • 127

20 Answers20

10

RegexBuddy is a widely popular app for this purpose. It also costs $40 and only runs on Windows.

For powerful free alternatives, see this answer.

Community
  • 1
  • 1
David Hanak
  • 10,754
  • 3
  • 31
  • 39
  • RegexBuddy is so good, I can't express it in 300 characters. Paid back whatever ($30 or $50) I paid for it within days. – MattBelanger Feb 18 '09 at 00:56
6

reAnimator is a nice tool to visualize your regex as a state machine- I find it useful sometimes.

Python also allows you to view a regex parse tree, which can be helpful if you learn to read it.

Community
  • 1
  • 1
Kenan Banks
  • 207,056
  • 34
  • 155
  • 173
6

Unit testing with example data. Create two arrays, one with matching data, and one with non-matching data if necessary to test edge cases.

Andrew Vit
  • 18,961
  • 6
  • 77
  • 84
  • Whilst I like manually driven tools, like RegExpBuddy, and an add-in that's available for IntelliJ, having some unit tests to increase the long-term chances of the expression remaining valid is always a good idea. – belugabob Jul 15 '09 at 09:59
4

Trial and error success.

Because I've spent the time to actually learn it, instead of relying on something else to do it for me.

Same applies to any language/tool - take a bit of time to learn the syntax and general ethos, and you'll be far more productive than relying on intellisense, code hinting, and so on.

Peter Boughton
  • 110,170
  • 32
  • 120
  • 176
  • 1
    Hear, hear! (And the regex language isn't nearly as complex as it seems at first glance... I get them right on the first try much more often than not.) – Dave Sherohman Jul 15 '09 at 09:54
  • I get them right by the third try much more often than not, but I'll get back to you in a few years. – Telemachus Jul 16 '09 at 12:48
4

There are powerful online tools. Offline,

  • The Regex Coach is a great free offline regex tool that I use fairly regularly.
  • I like RegEx Buddy also, but it costs $40 and I'm cheap.
Community
  • 1
  • 1
Chris Ballance
  • 33,810
  • 26
  • 104
  • 151
3

Expresso is free Windows program and gives nice breakup and explanation of the regex under analysis.

For online tools that you can run right away from a browser, see this answer.

Community
  • 1
  • 1
Learning
  • 8,029
  • 3
  • 35
  • 46
2

i always use this: http://gskinner.com/RegExr/

Lance Kidwell
  • 853
  • 1
  • 14
  • 18
1

Regex Buddy is overkill ($40) and works only on Windows. It was a good choice back in 2009 maybe.

Now we have free powerful online tools to build and test regular expressions. Regex101 is one of them:

  • lets you select the RE engine (PCRE, JavaScript, Python)
  • colorizes the matches
  • explains the regexp on the fly
  • has a debugger
  • can create permalinks to the regexp playground.

More regexp testing tools in my other answer.

Community
  • 1
  • 1
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
1

Trial and error.

And print_r.

strager
  • 88,763
  • 26
  • 134
  • 176
1

I really like RegexPal, which is simple, clear, requires no installation and freely available online.

Wookai
  • 20,883
  • 16
  • 73
  • 86
1

Online... there's an ajax regex checker with js/pcre/posix implementations, that checks as you type.. way cool.

http://www.rexv.org

null
  • 7,432
  • 4
  • 26
  • 28
0

I used to use The Regex Coach. But because it's Perl based and most of the time I'm testing .NET regular expressions, I now use this online .NET regular expression tester.

Steve Wortham
  • 21,740
  • 5
  • 68
  • 90
0

I liked the emacs re-builder.

Paul Nathan
  • 39,638
  • 28
  • 112
  • 212
0

I've written my own tool: Regular Expression Tester. Unlike many other web-based tools, this one can break a regex down into tokens and describe what each token is doing. It's great for examining new expressions, or expressions that you wrote a long time ago and don't quite remember.

Chris Nielsen
  • 14,731
  • 7
  • 48
  • 54
0

Since you're talking about PHP, you may be interested in Codebench. It is a tool, not specifically to break down regexes (you've got a lot of those listed already), but to benchmark them. Since it is rather generic, you can also compare non-regex solutions as often native string functions are faster. Moreover, it allows you to benchmark against multiple subjects (targets) as well. Hope you find it useful.

Geert
  • 1,804
  • 15
  • 15
0

I'm using unit-testing. That way, I can grow my regex incrementally, being certain that the first cases I tested still pass. And if ever I have to modify it, I have all my tests to back me up.

philant
  • 34,748
  • 11
  • 69
  • 112
0

For online test Regx http://www.regexr.com/ use this site and if your regx work on this then you can check it for php on writecodeonline.com with preg_match() function.

ankkuboss
  • 41
  • 1
  • 3
0

I wrote a python library to accomplish this, it is under cloudtb.re

text = 'so foo is the opposite of bar but without foo there is no bar?'
exp = '(foo).*?(bar)'
searched = cre.research(exp, text)
print(searched)

pprinted regular expression

vitiral
  • 8,446
  • 8
  • 29
  • 43
0

I generally use Rubular when I'm working on testing a regular expression. You could also try txt2re.com, it can be handy for helping you figure out an expression and can even generate relevant PHP code.

Chad Birch
  • 73,098
  • 23
  • 151
  • 149
0

Here is another online regular expression tester for Java:

http://www.fileformat.info/tool/regex.htm

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
JohnFx
  • 34,542
  • 18
  • 104
  • 162