Skip to content

Regular Expression

This is more of a note-to-self type of post.

You know that series of symbols and characters in a chain following each other? Sometimes you will find them with a find, replace, or find and replace function.

Examples:

  • This processes a URL:
  • somefunction.replace(/^http[s]{0,1}:\/\/[^\/]*\/?/, '/')
  • From WordPress: The following example removes all HTML comments in the first pattern, and causes a favicon (with any filename extension) to be loaded from another domain in the second pattern:
    #<!--.*?-->#s =>
    #\bsrc="/(favicon\..*)"# => src="http://mycdn.somewhere.com/$1"

Well, they are called regular expressions and you can learn more about them at some of these sites:

  • Wikipedia: https://en.wikipedia.org/wiki/Regular_expression
  • Regular-Expressions: http://www.regular-expressions.info/
  • Debuggex: https://www.debuggex.com/cheatsheet/regex/javascript
  • REGEX Library: http://regexlib.com/Default.aspx

Any comments, suggestions, or questions? Please drop a note.

Leave a Reply

Your email address will not be published.