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: Capitalize the First Character of All Words with Word Boundary Matches

There is a great use of regular expressions for converting the first character of all words to uppercase in sentence or paragraph since there’s the better option of using the Word Boundary Anchor \b. \b is special character in regular expressions to match a word boundary. A word boundary matches the position where a word […]

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: iframe: iframe (secure): object param: object embed: watch: users: ytscreeningroom: any/thing/goes!: any/subdomain/too: more params: Here is a PHP function with a commented regex that matches each of these URL […]

Continue reading