What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

Are regular expression questions not welcome at SO? Why? Here are two threads:

regex match failure

I replied to this unanswered four month old question only to receive immediate down votes with the explanation that the user shouldn't be using regex. I don't discount that advice for certain scenarios, but the user wanted a regex answer and was given one.

Then there is this question where it was closed after one hour

C# RegEx With Different Rules For First And Subsequent Characters [closed]

I replied to the user to try the MSDN regex forum in the comments since the post was closed. Learning regular expressions creates questions...just like .Net C# linq, but you don't see those questions closed. (Should that question be moved to code review instead?)

Now two questions don't indicate a pattern, but something is amiss when it comes to regex. Learning regex requires asking questions...to which Stack Overflow seems like an appropriate place to ask them.

Am I wrong?

I get that people have personal preference to not use regular expressions and that is fine; but when moderators or persons of stature apply their bias in Stack Overflow I believe that goes against the spirit of Stack Overflow.

Thoughts?

share|improve this question
6  
I wonder what, apart from RegEx may be a common denominator to these questions? –  Oded Jan 9 '12 at 18:51
6  
The pony he comes... –  Jack Maney Jan 9 '12 at 18:59
10  
Yes, there is some bias. You will notice that many commentors silently substitute "matching" for "parsing" whenever such a question comes up. Superficially this is a meme (you know that one famous off-topic joke answer). But subconcsiously this is a common reaction because misapplied regex questions become tiresome. Many posters treat regex as magic black box codez they don't have to learn, just ask for. With time that differentation fades however. –  mario Jan 9 '12 at 19:17
7  
Well maybe you should just use Jquery instead of regex. –  JNK Jan 9 '12 at 21:18
    
Confused at to why this question got downvoted - surely it's ok to ask? –  Highly Irregular Jan 15 '12 at 2:34
    
@HighlyIrregular I seem to only ask questions which people love to down vote. :-) See Cult of Personality and Paparazzi –  OmegaMan Jan 15 '12 at 15:33
1  
@HighlyIrregular - On Meta downvotes indicate disagreement. –  JNK Jan 16 '12 at 19:47

4 Answers 4

There's no bias against regular expression questions; I see them all the time in the JavaScript tag.

The first question was a horrible, horrible misapplication of regular expressions. As the comments pointed out, the OP should be using either LINQ to XML, or XPath. Still though, I don't agree with the downvote of your answer—I +1'd -- thank you meta-effect :) Consider adding a preface to your answer to the effect of

This should really, really be done with either LINQ or XPath, but if this is just a learning exercise, your problem is....


The second question was closed as too localized, which I really don't understand. Maybe Robert will chime in and clarify.

share|improve this answer
1  
+1, no reason why his answer should have been downvoted. –  user7116 Jan 9 '12 at 19:17
5  
I gave my reason. It's quite alright to disagree with my reason, but there is a reason. –  John Saunders Jan 9 '12 at 19:18
1  
Michael Myers is correct. I closed the second question because the OP says the Regex already worked. –  Robert Harvey Jan 9 '12 at 19:42
    
@Robert - thank you. –  Adam Rackis Jan 9 '12 at 19:59

I thought I made myself clear in the comments, but perhaps not.

As stated very clearly in "RegEx match open tags except XHTML self-contained tags", regular expressions, in general, should be used only for regular languages. HTML, XML, and other SGML variants are not regular languages, and regular expressions should not be used to parse them.

In my opinion, any answer other than "don't do that" does a disservice to the community. By showing code that "works" for specific cases, the impression is given that anyone who says not to use regular expressions is being pedantic - that it doesn't really matter. Anyone who believes that is giving himself the opportunity to find out the hard way that the advice against regular expressions in these cases is actually correct. As soon as the input gains nested tags, for instance, the code will break.

If you want to be helpful, then help them find a way to parse their string without using regular expressions.

share|improve this answer
    
I didn't disagree with your logic about using HTML agility pack or an xml parser. I actually support and agree with it 100%. Really But I felt downgrading my reply with an alternate answer in the comments, (though I appreciated you telling me why it was downgraded) was not the tack to take and it should have put as an an alternate answer instead. It was a case of don't shoot the messenger... –  OmegaMan Jan 9 '12 at 19:26
2  
Nested tags - bingo. that's why regex can never work for html –  Adam Rackis Jan 9 '12 at 19:59

Regarding your second link, the user who posted the question later posted a comment (now deleted):

Please accept my apologies, the RegEx I'm using does actually work. Go me.

He then flagged the question for moderator attention with basically the same message. That's why Robert Harvey closed it as Too Localized.

share|improve this answer
1  
I am not familiar with moderation on SO...but is there as category which states "Closed at the request of the OP"? –  OmegaMan Jan 9 '12 at 21:28
    
@OmegaMan: No, but Too Localized usually works if the question's premise is invalidated. See also meta.stackexchange.com/questions/118444/… –  mmyers Jan 9 '12 at 21:36

Are regular expression questions not welcome at SO? Why?

Good regular expression questions are welcome.

Bad regular expression questions are tolerated.

Many regular expression questions will be made fun of due to the fact that some developers tend to misapply them.

So yes, there is a bias, no they aren't unwelcome, but people who post them will often stub their toe if they are either using them for an application in which they will work poorly, or if the question is very simple. Basic regular expressions can become complicated quite quickly, though, so the second reason is rarely the problem.

In your first example, answers to regex questions which are fundamentally mis-applied may receive some downvotes for their trouble. A regular expression is used for parsing regular languages. The person is attempting to parse a context-free language. There are valid reasons why this is strongly discouraged in programming circles.

The second example was closed at the request of the person who posted the question.

share|improve this answer

You must log in to answer this question.

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