3

I find we have a very common class of problem here:

  • Someone needs to do some string manipulation
  • They recognise that a regex is one of the possible solutions, even if there are valid solutions which do not involve a regex.
  • They ask for a regex solution, and tag their problem .
  • Now other valid (or better) solutions that do not involve a regex are invalid answers.

When I find these questions, I ask if they need a regex solution, or if non-regex answers are OK too. Consistently, the asker says non-regex answers are fine too, so I edit the question so it isn't tagged and just asks for a general solution.

A recent example: Reversing a string and preserving words in quotes (The first revision asks for a regex)

I recognise we can catch these questions early and edit them, but is there more we can do? Is there anything we can do to prevent people from asking their string-manipulation questions like this in the first place?

5
  • @BenLee I'm trying to work out how to better ask this to make that clearer. :) Sep 18, 2013 at 0:19
  • So you basically want to educate users that regex is not a magic tool for any/all string manipulation? Sep 18, 2013 at 0:20
  • 9
    Did anybody ask these strings how they feel about being manipulated? Maybe they have a preference? </unhelpfulComment> Sep 18, 2013 at 0:21
  • 1
    @psubsee2003 Maybe? What I'd like is that if someone has a string manipulation problem, and they know that non-regex solutions exist, they don't just ask specifically for a regex solution. I can see educating users as being one means toward addressing this behaviour, but it isn't the ends I'm after in itself. Sep 18, 2013 at 0:22
  • 3
    "solutions that do not involve a regex are invalid answers" I totally disagree with that statement.
    – user159834
    Sep 18, 2013 at 0:31

2 Answers 2

6

First, always give a solution that answers the questioner's problem the way they want it answered - the OP might not be in control of other parts of the software that make the approach they are requesting not optimal, work politics, etc.

However, when you think you have a better approach, present it! Just make sure you answer the original questions first, then present your better approach and explain why it would be superior to the one they are asking for.

4

If you think regex is not the way to solve a certain problem, add your own non-regex solution, and explain why it's better.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .