I'm new and I would like to know where to start to learn regular expressions ?
I know this is a large question but I really want to know this.
Thanks a lot for links or constructive answers.
-
2http://regular-expressions.info/ – Spudley Jun 03 '13 at 12:50
-
[regex in general](http://www.regular-expressions.info/tutorial.html), [PHP specific](http://www.php.net/manual/en/reference.pcre.pattern.syntax.php), [The Hard Way](http://regex.learncodethehardway.org/book/). – HamZa Jun 03 '13 at 12:51
-
Well the question that you have asked doesn't seem constructive so how could you expect us to provide constructive answers. Anyways, http://regexone.com/ is a great site to learn about regular expression. – Vivek Sadh Jun 03 '13 at 12:55
-
I ask a question, I do not want your unconstructive comments. Thanks for your links for those who want help me. – Alfred Jun 03 '13 at 12:58
-
[Resources for Learning Regular Expressions](http://programmers.stackexchange.com/questions/49279/resources-for-learning-regular-expressions) – stema Jun 03 '13 at 13:25
-
[Mastering Regular Expressions (3rd Edition)](http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124 "By Jeffrey Friedl. Best book on Regex - ever!") - Hands down the most useful book I've ever read. _Highly_ recommended. – ridgerunner Jun 03 '13 at 13:39
2 Answers
Your question will be closed as it's not a real question but you'll find a lot documentation about regular expression (abbreviated regex or regexp) on Internet and on StackOverflow but here a beginning.
Following information comes from Wikipedia... http://regexone.com will help you learning regex with lessons.
Metacharacters:
. matches any single character
For example a.c matches "abc", etc., but [a.c] matches only "a", ".", or "c".
[ ] matches a single character that is contained within the brackets
For example, [abc] matches "a", "b", or "c". [a-z] specifies a range which matches any lowercase letter from "a" to "z". These forms can be mixed: [abcx-z] matches "a", "b", "c", "x", "y", or "z", as does [a-cx-z].
[^ ] matches a single character that is not contained within the brackets
For example, [^abc] matches any character other than "a", "b", or "c". [^a-z] matches any single character that is not a lowercase letter from "a" to "z".
^ matches the starting position within the string. In line-based tools, it matches the starting position of any line.
$ matches the ending position of the string or the position just before a string-ending newline. In line-based tools, it matches the ending position of any line.
( ) defines a marked subexpression. The string matched within the parentheses can be recalled later (see the next entry, \n).
\n matches what the nth marked subexpression matched, where n is a digit from 1 to 9.
* matches the preceding element zero or more times
For example, ab*c matches "ac", "abc", "abbbc", etc. [xyz]* matches "", "x", "y", "z", "zx", "zyx", "xyzzy", and so on. (ab)* matches "", "ab", "abab", "ababab", and so on.
{m,n} matches the preceding element at least m and not more than n times
For example, a{3,5} matches only "aaa", "aaaa", and "aaaaa". This is not found in a few older instances of regular expressions. BRE mode requires {m,n}.
Examples:
- .at matches any three-character string ending with "at", including "hat", "cat", and "bat".
- [hc]at matches "hat" and "cat".
- [^b]at matches all strings matched by .at except "bat".
- [^hc]at matches all strings matched by .at other than "hat" and "cat".
- ^[hc]at matches "hat" and "cat", but only at the beginning of the string or line.
- [hc]at$ matches "hat" and "cat", but only at the end of the string or line.
- [.] matches any single character surrounded by "[" and "]" since the brackets are escaped, for example: "[a]" and "[b]".

- 1,518
- 1
- 19
- 34
All major languages support Perl-compatible syntax with just minor variations, almost invariably on things like how whitespaces and end of line characters are counted. As a general rule, you can take any reference on Perl syntax and try it in jsfiddle.net.
In fact, I'd say that studying from Perl sources will probably give you the widest breadth of possible uses and quirks that are generally applicable across languages.

- 36,828
- 10
- 60
- 83