Skip to content

Instantly share code, notes, and snippets.

View nitayneeman's full-sized avatar

Nitay Neeman nitayneeman

View GitHub Profile
import db from 'db.server';
import MyClientComponent from 'MyComponent.client';
function MyServerComponent(props) {
const { id } = props;
const dataById = db.data.get(id);
return <MyClientComponent data={dataById} />;
}
import MyClientComponent from 'MyComponent.client';
function MyServerComponent(props) {
// For instance, the data could be fetched directly from a database
const { data } = props;
return <MyClientComponent data={data} />;
}
const regex = /t(e)(st(\d?))/g;
const str = 'test1test2';
// Using spread operator
const array = [...str.matchAll(regex)];
// Using `from` method
const array2 = Array.from(str.matchAll(regex));
const regex = /t(e)(st(\d?))/g;
const result = 'test1test2'.matchAll(regex);
const [matchingValue, matchingValue2] = result;
const regex = /t(e)(st(\d?))/g;
const result = 'test1test2'.matchAll(regex);
for (const matchingValue of result) {
console.log(matchingValue);
}
const regex = /t(e)(st(\d?))/g;
let matchingValue;
while ((matchingValue = regex.exec('test1test2')) !== null) {
console.log(matchingValue);
}
// Output:
// ["test1", "e", "st1", "1", index: 0, input: "test1test2", groups: undefined]
// ["test2", "e", "st2", "2", index: 5, input: "test1test2", groups: undefined]
const regex = /t(e)(st(\d?))/g;
const result = 'test1test2'.matchAll(regex);
const resultAsArray = [...result];
console.log(resultAsArray[0]); // ["test1", "e", "st1", "1", index: 0, input: "test1test2", groups: undefined]
console.log(resultAsArray[1]); // ["test2", "e", "st2", "2", index: 5, input: "test1test2", groups: undefined]
const regex = /t(e)(st(\d?))/g;
const result = 'test1test2'.matchAll(regex);
console.log(result); // [RegExpStringIterator]
We couldn’t find that file to show.
const regex = /t(e)(st(\d?))/;
const result = 'test1test2'.match(regex);
console.log(result); // ['test1', 'e', 'st1', '1', index: 0, input: "test1test2", groups: undefined]