
Regex 101 - adamnemecek
https://regex101.com/
======
irrational
Other Regex resources I like include:

[http://regexone.com/](http://regexone.com/)

[http://www.rexegg.com/](http://www.rexegg.com/)

[http://eloquentjavascript.net/09_regexp.html](http://eloquentjavascript.net/09_regexp.html)

[http://www.cheatography.com/davechild/cheat-
sheets/regular-e...](http://www.cheatography.com/davechild/cheat-
sheets/regular-expressions/)

[http://www.smashingmagazine.com/2009/06/essential-guide-
to-r...](http://www.smashingmagazine.com/2009/06/essential-guide-to-regular-
expressions-tools-tutorials-and-resources/)

[http://www.smashingmagazine.com/2009/05/introduction-to-
adva...](http://www.smashingmagazine.com/2009/05/introduction-to-advanced-
regular-expression</a></p>)

~~~
cdmckay
This one is great too: [http://regexr.com/](http://regexr.com/)

~~~
jajern
This is my go to when trying to figure out why a regex isn't working how it
should.

------
castratikron
It's all fun and games until you find out that the meaning of a regex is
implementation specific. I've found that a Python regex will accept an
unspecified newline byte/character before the $, while std::regex in GNU C++11
will not.

~~~
robert_tweed
This is very true and it always bugs me when some application or API supports
regex, but the documentation doesn't specify the grammar, usually saying it's
"standard regular expressions" \- which standard? Posix? PCRE? Something else?
Almost every flavour has some subtle differences and it's really, really
important to know what you are dealing with.

I do feel like these subtle differences are the main cause of bugs in programs
containing regexes; compounded by the fact they aren't super-readable,
especially for people who don't use them frequently.

Tools like this are IMO really valuable for code reviews and it's nice to see
that this one does have a flavour switch on the LHS with some of the main
implementations.

~~~
OskarS
I also can never remember which characters are magic and which are literal in
different implementations. This is mostly Vim's fault, where the rules are
impossible to remember and often conflict with other implementations. Given
that it's the most common regex thing I use day-to-day, it's very annoying.

~~~
EvilTerran
Yeah, I agree, vim's default regex syntax is infuriatingly inconsistent. I
pretty much always start my REs with "/\v"[0], to the point it's in my muscle
memory: I'll find myself looking at that in the cmdline before I've even
drafted the pattern in my head. (Then sometimes I'll realise I just want to
find an exact string full of symbols, and have to back up and capitalize the
"v".)

... I should probably come up with some mappings so the \v is inserted
automatically.

[0]
[http://vimdoc.sourceforge.net/htmldoc/pattern.html#/\v](http://vimdoc.sourceforge.net/htmldoc/pattern.html#/\\v)

------
BorisMelnik
For those that don't regex. I originally learned regex just so I could do
complex find/replace in Notepad++ (I work with large data sets) I can't begin
to say how many hours of work its saved me over the years, and how much money
for that matter.

The best / easiest way that I've taught regex is to pop open a text editor and
start searching for stuff. Start by searching for some letters, then a string
with spaces, then a line break. From there I point people towards stuff like
Apache config file conditionals / URL re-writes etc.

~~~
berntb
Best sources about regexps?

I thought I knew regexps, then I read "Mastering regular expressions". After
that I was embarrassed. :-)

~~~
BorisMelnik
hmmm not sure, I'd also like a good resource because mine is not really the
"mastering" type resource

~~~
iheartmemcache
Mastering Regular Expressions really is the seminal text, but I highly suggest
reading the O'Reilly Sed/awk book as well. They include full history behind
the evolution of the original line editor ed -> sed & g/re/p (etymologically
derived from g[lobally-replace]/re[gex]/p[rint]) -> awk. The original vi also
derived a lot of it's commands from 'ex' (the underlying editor, based on the
original ed).

All history aside, 1: Sed&awk 2: Mastering Regexp 3: The vim book has a great
chapter on regular expressions (it's been ~10 years since I've touched it, but
I remember being gifted a copy from a colleague of my father when I was in my
teens and it helped me grok it)

The glibc programming manual is actually really comprehensive.
kernel.org/docs/man-pages/ gives a pretty in depth analysis of POSIX.2 regex.
I'm sure Perldocs also have PCRE's very well documented.

------
Zalastax
Complement with [https://www.debuggex.com](https://www.debuggex.com) to also
get an interactive finite automata (this can really help with understanding
what's going on)

------
strictnein
Many hours spent here, trying to create the ultimate email regex, while
telling my PMs and managers that there was no such thing.

~~~
captaincrowbar
Been there, done that. There's only one way to check email addresses: /.+@.+/

Anything else is going to give you a false negative sooner or later. Yeah, you
can spend hours framing a complicated expression that carefully tests for
exactly what the current bucket of RFCs specify, but you're guaranteed to run
into an MTA somewhere that disagrees with you, and you can argue until the
cows come home that you're right and they're wrong, but it's still you that's
going to have to change to accommodate them in the end.

~~~
aroch
I would think you'd use: /.+@.+\\..+/

~~~
pmlnr
nope. root@localhost is a valid mail address.

~~~
aroch
How often are you validating email addresses for localhost!? Those are pretty
much never a valid email for >>>99% of applications

~~~
nothrabannosir
That's the whole point of the original post: don't bother thinking about it,
let the mta do that for you. The "@" is a courtesy to make sure people didn't
mistakenly put their name in. Don't validate, just do a sanity check.

~~~
strictnein
And people are just as likely to type an valid but incorrect email address as
a invalid email address.

~~~
nkrisc
That's why you also implement an email verification method if you actually
care that it's a correct email as well as valid.

------
2T1Qka0rEiPr
I love resources like this, and use them quite frequently when I need to write
anything with moderate complexity. If you're using Python and writing long
RegExs, I really recommend using a multi-line approach with re.VERBOSE to
provide helpful comments to your future-self/co-workers.

------
HCIdivision17
This is really slick. I've used it a few times just to get my capture groups
tested right, where pattern matching is needed over parsing. The fact it color
codes the Python named capture groups is just awesome: make a regex to match
the stuff you need, then slam it into another string via % and you've just
converted one string into another. There's tons of ways to do that, but when
your patterns are fast and loose, it makes the intent a bit easier to show. (I
also tend to use regex with comments, so they tend to be a bit more literate
and long... well, at least not _all_ line noise.)

------
glangdale
This is really, really good. We work on regex ourselves
(github.com/01org/hyperscan) and I will definitely point people towards this
when they are trying to figure regex out.

The only regret I have is that many of the interesting regexes we see in the
course of our work are not something which we can type into someone else's web
site. Fortunately there are others who have looked at the idea of making an
off-line version:

[https://github.com/firasdib/Regex101/issues/76](https://github.com/firasdib/Regex101/issues/76)

~~~
spartanatreyu
DevDocs.io handles this really well

------
Aldo_MX
I have used this website a lot in the past, it has greatly helped me debugging
complex expressions, I would love to see an electron port in the future.

------
Already__Taken
It would be nice to add a little 1-click test button to this that can look at
some of my sample string and auto-fuzz the pattern and see if some unexpected
results come up.

Regex is weird anyway but it's often a surprise just some weird string that's
close to what you thought you wanted comes up.

------
__krris
Did anyone notice that the site is built using React? The UI is so
interactive.

------
cableshaft
I recently upped my Regex-fu significantly this year, and Regex101 is the main
reason why. Also giving a presentation in the office on Regular Expressions
helped too :).

------
metasyn
I often teach people how to use regex w/in the context of my job and find this
tool invaluable because it allows for PCRE in addition to the more common JS
regex flavour.

------
bedros
best way to test a regex is to use sublime search, and you'll see all matching
strings inside the open text file interactively highlighted

~~~
_ao789
Weirdly enough I was actually playing around with this today instead of
completing an even more boring jira task :) ..what a life

------
leommoore
This is just the coolest way to test your regex is a great sandbox with lots
of feedback to help you get it right.

------
pmlnr
Donated once, will do more; the site saved the day too many times not to.

