Automatically generate regular expressions with Txt2re

Discuss

25 Responses to “Automatically generate regular expressions with Txt2re”

  1. Anonymous says:

    Woah weird, I used that today without this what a coincidence!

  2. CJR says:

    An alternate approach is this tool – called Poirot (Mac or Windows). It allows you to build RegEx via pattern fragments visually. http://www.espgraphics.com/poirot/

  3. Anonymous says:

    I know I’m an idiot, but what would someone use this for? I assume it is only for computer coders, but it is unclear as to what it means to the average person.

    • Robert says:

      @Anon: it would be used for coming up with regular expressions, if you’re a programmer who hates coming up with regular expressions. Good God, man, it says it right on the side of the tin.

  4. Anonymous says:

    Now they have three problems? ( http://lmgtfy.com/?q=now+they+have+two+problems )

  5. MollyMaguire says:

    Nice tool! Bookmarked.

  6. ColHapablap says:

    Apparently the * and + quantifiers are not at all a huge part of making regexes flexible…

  7. endymion says:

    This is terrible, right?

    Regular expressions are like any other code. They should be thought through carefully, and documented. Otherwise, no one will understand what’s going on, and the results will be unmaintainable.

    This is done with good intentions, but it’s a step in the wrong direction.

    • salsaman says:

      Kind of, but regular expressions can be done any number of ways. While the results from txt2re seem longer than what I usually put together, it seems useful as (1) a check of what you’ve already come up with and (2) a way to get ideas for pattern types you’ve never worked with before.

      Of course it would be awful if people relied on a tool like this to make their regular expressions and never actually figured out what they mean.

    • salsaman says:

      Kind of, but regular expressions can be done any number of ways. While the results from txt2re seem longer than what I usually put together, it seems useful as (1) a check of what you’ve already come up with and (2) a way to get ideas for pattern types you’ve never worked with before.

      Of course it would be awful if people relied on a tool like this to make their regular expressions and never actually figured out what they mean.

    • Guysmiley says:

      As much as I don’t like writing regex at times, I agree. If you don’t know how to write an expression and just auto-magically generate one you don’t really understand what it’s doing. The question is, is that better or worse than banging on a keyboard until something close to what you want happens, then using that?

      Regex can be annoying, but can be an incredibly useful time saver to us code monkeys.

  8. retchdog says:

    can this do anything more substantial than isolate a single substring?

    i would say that it’s a nice learning tool, except that it’s ugly and terrifying.

  9. Anonymous says:

    It’s missing stuff like repetition of patterns. It would be handy for someone who isn’t familiar with regular expressions.

  10. Wilks says:

    @Anon – http://en.wikipedia.org/wiki/Regular_expression

    I tend to think that this is a positive thing. The regex will need to be tested anyways, and as Guysmiley points out, many people iterate over and over one regex till they get it right – there’s a lot of guesswork as it stands.

    Also, I’ve never encountered anyone’s code that has the regex painstakingly explained out – one would simply end up rewriting most of the regex documentation. Certainly the target pattern or function is explained, but not the formulation of it.

  11. TSI says:

    Really…people are complaining that this tool is no good because someone who isn’t a RegEx geek could use it, effectively.

    Face it most code doesn’t get reused, it is a “Not Written By Me” thing.

    If this tool works, even if it makes non-optimal RegEx…who cares? 99.999% of the software in use is suboptimal but I don’t go sticking my nose in the air refusing to use it.

  12. Kieran O'Neill says:

    What does it mean to the average person? Something like this.

    But yeah, what all the other guys have said. It might be useful as a way of tinkering and getting a skeleton of what you want, but you really should understand how regexes work sufficiently to be able to tweak and streamline the output of this tool to suit your needs, or not use it at all.

  13. Pantograph says:

    Well thanks a lot! Now I will never gather up the courage to properly learn regular expressions!

  14. bardfinn says:

    For those who object on the basis that it creates results that are ugly, clunky, inelegant, unmaintainable: I will now relate what I was told by a Real Programmerâ„¢ (one who wrote out his programs in octal in pen on a code tablet and handed it over to a keypunch operator) and which has served me well ever since: Elegance is in the eye of the beholder, and maintainability is produced by documentation. If the code runs the way you need it to run for optimisation for memory usage or processor usage or maintainability or real-time speed, then that’s the elegance. Others don’t have to see it and often will never see it. If it makes sense to unroll a loop, unroll the loop. If the ugly regex works and does not require a maintenance programmer to understand a nuanced regex concept or operator, to debug somewhere down the line, then use it.

    At the same time, I will echo what others have asserted: If you don’t know what you’re doing, the code could be doing anything and returning what you want to see some of the time. Please understand the results or it’s just as bad as writing code that never returns the results you want.

    • retchdog says:

      the problem is that this machine doesn’t optimize for anything, while being very restricted in what it can do. on the plus side, it is so restricted that it’s almost impossible to be surprised by its output! :)

      if you want to understand and extrapolate someone else’s regex, there are, i think, much nicer tools for that which use color-coding to tag which pieces of the string are captured by which parts of the regex. google “regex explorer” for many examples.

  15. Anonymous says:

    Really? You guys know how the compiler works, the internals of the cp command, etc? No, you don’t. But you use them. Same thing with this. I don’t really care HOW it works, but IF it works.

  16. Anonymous says:

    Bah!

    as an unemployed tech (willing stay-at-home-dad) this saddens me.

    I used to be known as “tool” at my former software job I sat around all day creating scripted tools for engineers and artists to facilitate workflow. The essence of my job was writing Perl scripts parsing files. I was a RegEx monkey.. and I loved it and hope to return to being a similar monkey or SQL squirrel (debugging databases).

    This tool is taking my job! (or making it easier?!?) ;)

  17. nosehat says:

    The programmer explains, “It’s free because I have been helped in my career so much by the programmers who generated free systems like linux, apache, php and mysql – this is the only free labour that I have ever given back to the community.

    Unless I missed a link, he’s not sharing his source code. Cool tool and all, but it doesn’t look like it’s something one could take and improve upon.

  18. Daemon says:

    I only use regex for personal projects – filtering RSS feeds via Pipes, for example. I don’t use it enough to have any interest in learning all the ins and outs – I just want to make it work.
    This is perfect for me.

  19. Modus Tollens says:

    This one is pretty sweet, too:
    http://gskinner.com/RegExr/

    And I’ve always loved this quote, although it’s not clear that Jamie Zawinski actually said it:

    ‘Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.’

    http://en.wikiquote.org/wiki/Jamie_Zawinski#Attributed

  20. kmoser says:

    Dang. I’m pretty fluent in regexps but I can’t fathom that interface if my life depended on it.

Leave a Reply