Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

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?

share|improve this question
Jonathan, just in case you're wondering, I deleted my answer because I no longer think it applies in light of a correct interpretation of your question. – Ben Lee Sep 18 '13 at 0:19
@BenLee I'm trying to work out how to better ask this to make that clearer. :) – doppelgreener Sep 18 '13 at 0:19
So you basically want to educate users that regex is not a magic tool for any/all string manipulation? – psubsee2003 Sep 18 '13 at 0:20
Did anybody ask these strings how they feel about being manipulated? Maybe they have a preference? </unhelpfulComment> – Andrew Barber Sep 18 '13 at 0:21
@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. – doppelgreener Sep 18 '13 at 0:22
@JonathanHobbs What exactly are you looking for with this question? You can't prevent people from asking for regex, and as you stated people are generally open to other solutions. Your example isn't very strong, the OP simply says "I tried to figure out a way to do this using regular expressions but that didn't help", he doesn't ask for a regex explicitly. Both answers use a regex. What's the issue? – Wesley Murch Sep 18 '13 at 0:27
@JonathanHobbs beyond what you are doing, I don't see another solution. Any tag specific warning messages have been ruled out before in another similar question (can't find the one I am looking for). So what else is left? Are you looking for ideas? – psubsee2003 Sep 18 '13 at 0:30
"solutions that do not involve a regex are invalid answers" I totally disagree with that statement. – Wesley Murch Sep 18 '13 at 0:31
@Wesley I just realised you're right about this example. Other examples are way back in my edit summary history, so I can't dig for a better one at the moment. I'll let this question be closed as unclear for the time being if it needs to be. – doppelgreener Sep 18 '13 at 1:08
@psubsee2003 Yes, I'm looking for ideas. Possibly there isn't another solution. – doppelgreener Sep 18 '13 at 1:08
@Wesley When a JavaScript question gets a jQuery answer, the answer is voted down as not meeting the requirements of the question (they're not necessarily using jQuery). Similarly, if a question explicitly asking for a regex gets a non-regex answer, wouldn't that get voted down for not meeting the requirements of the question? – doppelgreener Sep 18 '13 at 1:56
@JonathanHobbs It's the opposite. People on SO are fond of pointing out when you don't need regex or jQuery. – Wesley Murch Sep 18 '13 at 3:09
@Wesley Well, giving a jQuery answer to a JavaScript question is its own class of "don't do that". If non-regex solutions to a regex question are totally OK, then that's excellent and I guess not much more needs to be done. – doppelgreener Sep 18 '13 at 3:23

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.

share|improve this answer

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.

share|improve this answer

You must log in to answer this question.

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