Short tips of regex - http://immike.net/blog/2007/06/21/extreme-regex-foo-what-you-need-to-know-to-become-a-regular-expression-pro/ Let regex more readable - http://martinfowler.com/bliki/ComposedRegex.html Useful Regular regression Match username - /^[a-zA-Z0-9_]{3,16}$/ Matching an XHTML/XML tag - {]*>(.*?)} Matching an XHTML/XML tag with a certain attribute value (e.g. class or tag) - {]*attribute\\s*=\\s*(["'])value\\\\1[^>]*>(.*?)} Matching a URL - (a very long one... refer to article...) http://immike.net/blog/2007/04/06/5-regular-expressions-every-web-programmer-should-know/ The danger of bad regex - http://andreas.haufler.info/2013/09/how-to-kill-java-with-regular-expression.html http://www.regular-expressions.info/catastrophic.html http://vladmihalcea.com/2014/02/24/the-regex-that-broke-a-server/ You have a string “BEFOREAFTER”. If this string has a ‘x’ in it, you want to capture everything before the ‘x’, else you want to capture the whole string. So, ”BEFOREAFTER” gives “BEFOREAFTER” ”BEFORExAFTER” gives “BEFORE” http://octodecillion.com/blog/regexp-group-capture-with-optional-delimeter/#solution http://www.infoq.com/cn/articles/regular-expressions-introduction-part01 https://www.guru99.com/linux-regular-expressions.html https://www.janmeppe.com/blog/regex-for-noobs/