regex special characters javascript 1

regex special characters javascript

// Tests website Regular Expression against document.location (current page url)
if (https://cdn.myedukit.com/^https\:\/\/example\.com\/$/.exec(document.location)){
	console.log("Look mam, I can regex!");
}

Here is what the above code is Doing:
1. We’re creating a new variable called “regex” and assigning it a value of a Regular Expression.
2. We’re testing the Regular Expression against the current page url.
3. If the Regular Expression matches the current page url, we’re logging a message to the console.

The Regular Expression we’re using is:
^https\:\/\/example\.com\/$

Here’s what it means:
^ – The beginning of the string
https\:\/\/ – The string “https://”
example\.com – The string “example.com”
\/ – The string “/”
$ – The end of the string

So, the Regular Expression is looking for a string that starts with “https://”, followed by “example.com”, followed by “/”, and ends there.

If the current page url matches that pattern, the code inside the if statement will run.

You can use Regular Expressions to test for any pattern you want.

For example, if you wanted to test for a url that starts with “https://” and ends with “.com”, you could use this Regular Expression:
^https\:\/\/.*\.com$

Here’s what it means:
^ – The beginning of the string
https\:\/\/ – The string “https://”
.* – Any character, any number of times
\.com – The string “.com”
$ – The end of the string

You can use Regular Expressions to test for any pattern you want.

For example, if you wanted to test for a url that starts with “https://” and ends with “.com”, you could use this Regular Expression:
^https\:\/\/.*\.com$

Here’s what it means:
^ – The beginning of the string
https\:\/\/ – The string “https://”
.* – Any character, any number of times
\.com – The string “.com”
$ – The end of the string

You can use Regular Expressions to test for any pattern you want.

For example, if you wanted to test for a url that starts with “https://” and ends with “.com”, you could use this Regular Expression:
^https\:\/\/.*\.com$

Here’s what it means:
^ – The beginning of the string
https\:\/\/ – The string “https://”
.* – Any character, any number of times
\.com – The string “.com”
$ – The end of the string

You can use Regular Expressions to test for any pattern you want.

For example, if you wanted to test for a url that starts with “https://” and ends with “.com”, you could use this Regular Expression:
^https\:\/\/.*\.com$

Here’s what it means:
^ – The beginning of the string
https\:\/\/ – The string “https://”
.* – Any character, any number of times
\.com – The string “.com”
$ – The end of the string

You can use Regular Expressions to test for any pattern you want.

For example, if you wanted to test for a url that starts with “https://” and ends with “.com”, you could use this Regular Expression:
^https\:\/\/.*\.com$

Here’s what it means:
^ – The beginning of the string
https\:\/\/ – The string “https://”
.* – Any character, any number of times
\.com – The string “.com”
$ – The end of the string

You can use Regular Expressions to test for any pattern you want.

For example, if you wanted to test for a url

Similar Posts