JavaScript Query String Getting and Parsing to Object with Regular Expression

What is Query String Query string is the part of a uniform resource locator (URL) containing data that does not fit conveniently into a hierarchical path structure. It commonly includes fields (requested pairs of key and value) added to a base URI by a Web browser or other client application, for example

The first […]

Continue reading


JavaScript Generate UUID/GUID for RFC 4122 Version 4 Compliant with Regular Expression

What is UUID/GUID A Universally Unique IDentifier (UUID) – also called a Global Unique IDentifier (GUID) – is a 128-bit value formatted into blocks of hexadecimal digits separated by a hyphen (‘-‘ U+002D). A typical UUID is baef6775-eb3a-4ac9-85d3-70e4aa0d9d94. A version 4 UUID is defined in RFC 4122: 128 randomly-generated bits with six bits at certain […]

Continue reading


Regular Expression: Count the Number of Occurences of a Character in a String

Use a RegEx to count the number of “o” occurs in a string.

Let me explain how this works: str.match() is a RegEx method. It searches for the specified RegEx inside the specified string (in this case, the string is “str“). (/o/gi) This is the actual RegEx. It reads, “find the character o” It’s […]

Continue reading


Regular Expression: Match Line Not Containing a Specific Word

Here means to explain how to match lines not containing a specific word (e.g. codingrepo) using regular expression.

The notion that regex doesn’t support inverse matching is not entirely true. You can mimic this behavior by using negative look-arounds:

The regex above will match any string, or line without a line break, not […]

Continue reading


Regular Expression: Remove spaces from a string with JavaScript

When we have a string that contains space characters:

and we want to remove the spaces from the string (we want this: ‘ABCDEF’). Both this:

and this:

will return the correct result. \s means “one space”, and \s+ means “one or more spaces”. In the first regex, each space character is being […]

Continue reading


Regular Expression: Converting Youtube Video Watch URL to Embed URL

A YouTube video URL may be encountered in a variety of formats: latest short format: http://youtu.be/NLqAF9hrVbY iframe: http://www.youtube.com/embed/NLqAF9hrVbY iframe (secure): https://www.youtube.com/embed/NLqAF9hrVbY object param: http://www.youtube.com/v/NLqAF9hrVbY?fs=1&hl=en_US object embed: http://www.youtube.com/v/NLqAF9hrVbY?fs=1&hl=en_US watch: http://www.youtube.com/watch?v=NLqAF9hrVbY users: http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo ytscreeningroom: http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I any/thing/goes!: http://www.youtube.com/sandalsResorts#p/c/54B8C800269D7C1B/2/PPS-8DMrAn4 any/subdomain/too: http://gdata.youtube.com/feeds/api/videos/NLqAF9hrVbY more params: http://www.youtube.com/watch?v=spDj54kf-vY&feature=g-vrec Here is a PHP function with a commented regex that matches each of these URL […]

Continue reading