Questions tagged [regular-expressions]

According to Wikipedia, a regular expression (abbreviated regex or regexp) is a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. "find and replace"-like operations.

According to Wikipedia, a regular expression (abbreviated regex or regexp) is a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. "find and replace"-like operations.

91 questions
200
votes
17 answers

What is meant by "Now you have two problems"?

There is a popular quote by Jamie Zawinski: Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. How is this quote supposed to be understood?
IQAndreas
  • 2,675
  • 3
  • 15
  • 20
167
votes
10 answers

Is there a specific reason for the poor readability of regular expression syntax design?

Programmers all seem to agree that readability of code is far more important than short-syntaxed one-liners which work, but require a senior developer to interpret with any degree of accuracy - but that seems to be exactly the way regular…
J.Todd
  • 3,833
  • 5
  • 22
  • 27
109
votes
25 answers

How far should one take e-mail address validation?

I'm wondering how far people should take the validation of e-mail address. My field is primarily web-development, but this applies anywhere. I've seen a few approaches: simply checking if there is an "@" present, which is dead simple but of course…
Lauren
  • 1,259
  • 2
  • 8
  • 9
86
votes
12 answers

Readable regular expressions without losing their power?

Many programmers know the joy of whipping up a quick regular expression, these days often with help of some web service, or more traditionally at interactive prompt, or perhaps writing a small script which has the regular expression under…
hyde
  • 3,744
  • 4
  • 25
  • 35
86
votes
23 answers

Is it a must for every programmer to learn regular expressions?

I am new to programming, and at an interview I got a question on regular expressions; needless to say I couldn't answer. So I was wondering whether I should learn regular expression? Is it a must for every programmer of all fields? Or it is a must…
user
  • 2,170
  • 8
  • 25
  • 36
81
votes
18 answers

How do you learn Regular Expressions?

I'm not asking where to learn. I've found lots of good resources online, and books etc. But how the heck do I tackle them. Where is the start of it, the end? When does the regexp processor advance on the text, when does it hold its stand and tries…
dumbBoy
  • 11
  • 3
  • 7
50
votes
5 answers

When you should NOT use Regular Expressions?

Regular expressions are powerful tool in programmer's arsenal, but - there are some cases when they are not a best choice, or even outright harmful. Simple example #1 is parsing HTML with regexp - a known road to numerous bugs. Probably, this also…
c69
  • 1,358
  • 1
  • 12
  • 19
38
votes
4 answers

Are regular expressions a programming language?

In the academic sense, do regular expressions qualify as a programming language? The motivation for my curiosity is an SO question I just looked at which asked "can regex do X?" and it made me wonder what can be said in the generic sense about the…
Aaron Anodide
  • 5,463
  • 5
  • 28
  • 37
36
votes
0 answers

What does the Jamie Zawinski's quotation about regular expressions mean?

In a message to comp.emacs.xemacs, Jamie Zawinski once said: Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. I've always had trouble understanding what he was getting at. What…
Paul Biggar
  • 1,207
  • 9
  • 11
35
votes
6 answers

Should there be unit tests for complex regular expressions?

Should I write unit tests for complex regular expressions in my application? On the one hand: they are easy to test because input and output format is often simple and well-defined, and they can often become so complex so tests of them specifically…
Lii
  • 461
  • 4
  • 7
32
votes
7 answers

How do regular expressions actually work?

Say you have a document with an essay written. You want to parse this essay to only select certain words. Cool. Is using a regular expression faster than parsing the file line by line and word by word looking for a match? If so, how does it work? …
lazeR
  • 439
  • 1
  • 4
  • 5
31
votes
6 answers

Is exposing regex in error response to end user bad practice?

Say I have a have request payload PUT /user { email: "invalid" ... } In the backend there is a email regex, which I cannot modify. Currently the behavior is to output: { "error": "'email' fails to pass regex ''` } Should I…
夢のの夢
  • 427
  • 1
  • 4
  • 5
27
votes
5 answers

Can the csv format be defined by a regex?

A colleague and I have recently argued over whether a pure regex is capable of fully encapsulating the csv format, such that it is capable of parsing all files with any given escape char, quote char, and separator char. The regex need not be…
Spencer Rathbun
  • 3,576
  • 1
  • 21
  • 28
23
votes
17 answers

Why are regular expressions so morbidly attractive?

Exhibit 1, Exhibit 2, I guess you won't find it hard to recall other examples. Thing is: if there is more than one way to solve a problem, the PHP programmer (I usually browse the PHP tag on StackOverflow) will ask for help on the solution involving…
cbrandolino
  • 1,999
  • 1
  • 18
  • 21
15
votes
7 answers

Should I refactor large functions that mostly consist of one regex?

I just wrote a function that spans approximately 100 lines. Hearing that, you are probably tempted to tell me about single responsibilities and urge me to refactor. This is my gut instinct as well, but here is the issue: The function does one thing.…
1
2 3 4 5 6 7