tags:

views:

90

answers:

3

I've heard lots of talk about "Regex"es. I know that stands for "Regular Expression" but I'd like to learn more.

1) Is an expression a section of code?
2) If so how does this differ from other code?
3) Why is it called an expression?
4) What makes a section of code an expression?
5) Are there irregular expressions?

A: 

You might also try reading the most popular questions tagged regex here.

For example, Learning Regular Expressions has a lot of material for you.

DOK
A: 

1) Yes, sort of. A "Normal" expression would be anything that results in a value, like (x + 4) / 3 or sqrt(25). A Regular Expression is something different, though.

2) An expression is usually the right-hand side of an assignment statement or part of a conditional. A Regular Expression is something different, though.

3) Because someone named it that. ;) It doesn't have much to do with a mathematical expression or a normal programming expression AFAIK.

4) Depending on the language, it's a regex because of the syntax. For example in javascript, you know a regex when you see one, because either the regex literal syntax is used, ie. var re = /.*/g; or the RegExp constructor is used, ie. var re = new RegExp('/.*/', 'g')

5) Nope.

edit:

I've been informed that my answer for #3 is incorrect... It's called a regular expression because it's meant to parse regular languages, which tie in closely with computater science and mathematics.

alt text

no
This is fairly incorrect, especially #3. The name is related to the definition of *regular language*, a kind of formal language studied in theoretical computater science, a field fairly closely related to (discrete) mathematics.
You
@You: Feel free to edit my answer, as long as the word "computater" doesn't appear in it ;)
no
Meh, that's what I get for temporarily confusing "computational" and "computer".
You