Skip to content

Instantly share code, notes, and snippets.

View alexandreservian's full-sized avatar

Alexandre Servian alexandreservian

View GitHub Profile
@alexandreservian
alexandreservian / regex.md
Last active June 25, 2024 16:59
Metacaracteres Regex

Representantes

Meta Nome Função
. ponto um caractere qualquer
[] conjunto conjunto de caracteres permitidos
[^] conjunto negado conjunto de caracteres proibidos

Quantificadores

const regex = /(\((\d{2})\)\s?)?(\d{4,5})[-]?(\d{4})/gm;
console.log(regex.test('(77) 95684-9783')); //true
console.log(regex.test('(68)90499-9922')); //false
console.log(regex.test('95088-2649')); //true
@alexandreservian
alexandreservian / metodo-match.js
Created January 30, 2020 15:41
Método match
const text = `
- 58204-824
- 69337-978
- 69.938-863
- 7287498
`;
const regex = /(\d{2}[.]?\d{3})[-]?(\d{3})/gm;
console.log(text.match(regex));
// [ '58204-824', '69337-978', '69.938-863']
@alexandreservian
alexandreservian / metodo-replace.js
Created January 30, 2020 16:37
Método replace
const text = "É só o amor, é só o amor Que conhece o que é verdade";
const regex = /o\samor/gi;
console.log(text.replace(regex, "a dor"))
//É só a dor, é só a dor Que conhece o que é verdade
@alexandreservian
alexandreservian / metodo-replace-grupos.js
Created January 30, 2020 16:41
Método replace manipulando grupos
const text = "2019-26-09";
const regex = /(\d{4})-(\d{2})-(\d{2})/g;
console.log(text.replace(regex, "$2/$3/$1"));
// 26/09/2019
@alexandreservian
alexandreservian / metodo-replace-com-funcao.js
Created January 30, 2020 16:47
Método replace com função
const texto = `
Lista de jogos:
- Red dead redeption 2: R$ 180,00;
- The last of us 2: R$ 199,95;
- Resident Evil 2 remake: R$ 140,50;
`;
const regex = /(R\$)\s(\d*,\d*)/gmi;
const funcao = (match, p1, p2) => {
const real = parseFloat(p2.replace(/,/g,'.'));
const cotacao = 4.21;
@alexandreservian
alexandreservian / column-definition.js
Created February 13, 2020 01:15
Definição das colunas da tabela.
export default [
{
dataKey: 'id',
title: 'Código',
width: 100,
sortable: true,
align: 'center'
},
{
dataKey: 'thumbnail',
@alexandreservian
alexandreservian / mewtwo.js
Created February 13, 2020 01:35
Definição de um pokemon
{
id: 150,
name: 'Mewtwo',
thumbnail: "./assets/thumbnails/150.png",
type: [
'Psychic'
],
hp: 106,
attack: 110,
defense: 90,
@alexandreservian
alexandreservian / table-simples.js
Created February 13, 2020 01:47
Examplo de tabela
const App = () => {
return (
<Table
data={data}
>
{columnDefinition.map(({dataKey, ...restProps}) => (
<Column key={dataKey} dataKey={dataKey} {...restProps} />
))}
</Table>
);
@alexandreservian
alexandreservian / tabela-final.js
Created February 13, 2020 01:52
Tabela final
const App = () => {
return (
<Table
data={data}
loading={loading}
rowKey="id"
headerHeight={45}
rowHeight={70}
sortBy={sortBy}
onColumnSort={handleOnColumnSort(data, setData, setSortBy)}