Loading...
(function(){<br />
let canvas = document.createElement('canvas'),<br />
ctx = canvas.getContext('2d'),<br />
w = canvas.width = innerWidth,<br />
h = canvas.height = innerHeight,<br />
particles = [],<br />
properties = {<br />
bgColor : 'rgba(17, 17, 19, 1)',<br />
particleColor : 'rgba(255, 40, 40, 1)',<br />
particleRadius : 3,<br />
particleCount : 60,<br />
particleMaxVelocity : 0.5,<br />
lineLength : 150,<br />
particleLife : 6,<br />
};<br />
<br />
document.querySelector('body').appendChild(canvas);<br />
<br />
window.onresize = function() {<br />
w = canvas.width = innerWidth;<br />
h = canvas.height = innerHeight;<br />
}<br />
<br />
class Particle {<br />
constructor() {<br />
this.x = Math.random()*w;<br />Loading...
A great tool for testing regular expressions:https://regexr.com/
You can enter text for testing and immediately see what your regex matches. The tool also provides hints explaining what each part of the expression does.
[abc] — Matches either a, b, or c.[^abc] — Matches any character except a, b, or c.[a-q] — Matches any lowercase letter from a to q.[A-Q] — Matches any uppercase letter from A to Q.[0-7] — Matches any digit from 0 to 7.() — Groups multiple tokens together. It also creates a capturing group, allowing you to extract the matched substring or reference it later with a backreference.(a|b) — Matches either a or b.(?:...) — Groups multiple tokens together without creating a capturing group.For example, without grouping, in the regular expression /al{1,3}/gi, the quantifier applies only to the letter l. If you want the quantifier to apply to the entire sequence al, you need to group it:
/al{1,3}/gi → matches al, all, alll/(al){1,3}/gi → matches al, alal, alalal1const string =2 "Alice was born on January 15, 1990, and her email address is alice@email.com. Bob, on the other hand, was born on March 5, 1985, and his email address is bob@email.com. They both love programming and often visit websites like www.example.com and www.samplewebsite.org.";34console.log(string.match(/^a/gi));5// return [ 'A' ]67console.log(string.match(/\.$/g));8// return [ '.' ]
Lookbehind
(?<=...) — Positive lookbehind. Matches what comes after the specified pattern without including the pattern itself in the result.(?<!...) — Negative lookbehind. Matches only if the preceding text does not match the specified pattern.For example:
/(?<=[tT]he)./g — Matches the character immediately after the or The./(?<![tT]he)./g — Matches any character except those immediately preceded by the or The.Lookahead
(?=...) — Positive lookahead. Matches what comes before the specified pattern without including the pattern itself in the result.(?!...) — Negative lookahead. Matches only if the following text does not match the specified pattern. In other words, it excludes matches that are immediately followed by the given pattern.examples:
1console.log(`email`.match(/(?<=ma)./g));2// return [ 'i' ]34console.log(`email`.match(/.(?=ma)/g));5// return [ 'e' ]
.replace() String MethodWith this method, we can find specific characters or patterns and replace them in a string.
1const someString = `This is a test string with numbers (123) and symbols @#$. It also has words like "apple" and "banana." The temperature is 65°F.`;23console.log(someString.replace(/["()]/g, ""));4// return This is a test string with numbers 123 and symbols @#$. It also has words like apple and banana. The temperature is 65°F.
.match() String MethodThe .match() method searches for a match in a string. If a match is found, it returns an array; if no match is found, it returns null.
1const someString = `This is a test string with numbers (123) and symbols @#$. It also has words like "apple" and "banana." The temperature is 65°F.`;23console.log(someString.match(/[tT]h(is|e)/g));4// return [ 'This', 'The' ]
.search() String MethodThe .search() method tests a string for a match. It returns the index of the first match. If no matches are found, it returns -1.
1const someString = `This is a test string with numbers (123) and symbols @#$. It also has words like "apple" and "banana." The temperature is 65°F.`;23console.log(someString.search(/\d/));4// return 36
.split() String MethodUsing a regular expression, we can split a string into substrings.
1const someString = `The temperature is 65°F.`23console.log(someString.split(/\s/));4// return [ 'The', 'temperature', 'is', '65°F.' ]
.test() Regular Expression MethodThe .test() method searches for a match in a string using the specified regular expression and returns true if a match is found or false if no match is found.
1const someString = `This is a test string with numbers (123) and symbols @#$. It also has words like "apple" and "banana." The temperature is 65°F.`;23const regExp = /\d/g;4console.log(regExp.test(someString)); //true
.exec() Regular Expression MethodThe .exec() method also searches for a match in a string, but unlike .test(), it returns an array containing the first match or null if no match is found.
1const someString = `This is a test string with numbers (123) and symbols @#$. It also has words like "apple" and "banana." The temperature is 65°F.`;23console.log(regExp.exec(someString));4// return [5// '(',6// index: 35,7// input: 'This is a test string with numbers (123) and symbols @#$. It also has words like "apple" and "banana." The temperature is 65°F.',8// groups: undefined9// ]