RegExp, RegExr

김용희·2022년 10월 27일
0
const regexs =
  /^[\uac00-\ud7af]|[\u1100-\u11ff]|[\u3130-\u318f]|[\ua960-\ua97f]|[\ud7b0-\ud7ff]|[-+#()[\]%&,.:/㈜㈔內 ]{2,26}$/g;

const testTxtx = '테스트\\';
console.log('testText : ', testTxtx.replace(/\\/gi, ''));

const regex = new RegExp(/^[ㄱ-힣a-zA-Z\d\-+#()[\]%&,.㈜㈔'`/\t\s]+$/gi);
if (!regex.test(regex) || regex.trim().indexOf('ㆍ') !== -1) {
  alert('키워드는 한글, 영문, 숫자, 일부 특수문자 (- + # () [] % & . (주) (사) / )만 입력할 수 있습니다.');
  return;
}

============================================================

function HighlightedText({ text, highlightedText }: HighlightedTextProps) {
const removeBackslash = highlightedText.replace(/\\/gi, '');

============================================================

  const validationKeyword = (highlightedText: string) => {
    if (highlightedText.length > 20) {
      return alert('키워드는 20자 이내로 입력할 수 있습니다.');
    } else if (highlightedText !== '') {
      const regex = new RegExp(/^[ㄱ-힣a-zA-Z\d\-+#()[\]%&,.㈜㈔'`/\t\s]+$/gi);
      if (!regex.test(highlightedText) || highlightedText.trim().indexOf('ㆍ') !== -1) {
        alert('키워드는 한글, 영문, 숫자, 일부 특수문자 (- + # () [] % & . (주) (사) / )만 입력할 수 있습니다.');
        return;
      }
      return highlightedText;
    }
  };
 const resultRegexp = validationKeyword(highlightedText);

regExr 사이트
https://regexr.com/

regExr 함수
https://velog.io/@hanei100/%EC%A0%95%EA%B7%9C%ED%91%9C%ED%98%84%EC%8B%9D-%EB%A9%94%EC%86%8C%EB%93%9C

자바스크립트 replace 의 gi의 뜻
replace(/./gi, "")
g : 발생할 모든 pattern에 대한 전역 검색
i : 대/소문자 구분 안함
m : 여러 줄 검색

profile
He threw his knapsack over the brick wall

0개의 댓글