정규식 표현 정리

2019. 3. 28. 10:53

역슬레쉬

'use strict';

const string = '<h1>::: buy - 99,000 won :::</h1>';
const result1 = string.replace(/<h1>/g, '');
console.log('result1 :', result1);


const result2 = string.replace(/<h1>/g, '').replace(/<\/h1>/g, '');

// 역슬러쉬 정규식 표현시 앞에 사용
console.log('result2 :', result2);


 

.점

const string = '<h1>::: buy - </h1> <h2> 99,000 won :::</h2>';


const result1 = string.replace(/<..>/g, '');       // <..> 괄호속 어떤 문자2개면 삭제
const result2 = string.replace(/<.../g, '');        // <...  왼괄호 후  문자열3개 삭제


console.log('<..> : ', result1);
console.log('<...> : ', result2);

 

중괄호

'use strict';


const string = '<h1>::: buy - </h1> <h2> 99,000 won :::</h2>';
const stringDiv = '<div>::: buy - </div> <h2> 99,000 won :::</h2>';

const replaceH1 = string.replace(/<.{0,1}h1> /g, '');  // h1앞에 0,1글짜
const replaceTags = string.replace(/<.{0,4}> /g, '');  // > 앞에 0,4글짜

console.log(replaceH1);
console.log(replaceTags);

 

[]

const string = '<h1>::: buy - </h1> <h2> 99,000 won :::</h2>';

const Bracket = string.replace(/[()]/g, '');
const BracketComma = string.replace(/[()/\-,]/g, '');

 


console.log('before 전: ', string);
console.log('()after : ', Bracket);
console.log('/after : ', BracketComma);

 

 

 

 

'' 카테고리의 다른 글

express + morgan  (0) 2019.04.01
promise  (0) 2019.03.28
DB에 웹쉘코드 삽입 POC  (0) 2018.12.06
워드프레스 서버 이관  (0) 2018.09.03
PHPMailer 구글 SMTP 메일 보내기  (0) 2018.08.23
블로그 이미지

iesay

,