Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- jwt 헤더
- 테스팅
- 타임리프 참조 오류
- 배포 자동화
- git 폴더 모으기
- vue 추가
- prefilight
- AWS 생성
- 깃허브 토큰 발급
- deploy.sh
- ..gitignore
- vue 실행
- 채팅 프로젝트
- Quartz 라이브러리
- 클래스 참조
- 되돌리기
- jwt 필터
- CI/CD
- 깃허브 토큰 생성
- 소프트웨어
- Quartz dependency
- 환경변수
- EL1021E
- 배열 call by value
- dbeaver 백업/복구
- .ppk
- options 처리
- submit 기본동작
- Jenkins
- reset
Archives
- Today
- Total
lty's Blog
js 정규식 문자열 변환 본문
replace 함수 사용 시 문자열을 쉽게 변환할 수 있지만 Java 같은 replaceAll 함수가 없어 첫 번째 문자열 한 개만 변환 가능하다.
let string = "Hello word Hello word Hello word";
console.log("After:"+string);
string = string.replace("Hello", ""); /* => word Hello word Hello word*/
console.log("Before:"+string);
정규식 사용
let string = "Hello word Hello word Hello word";
console.log("After:"+string);
string = string.replace(/Hello/g, "");
console.log("Before:"+string); /* => word word word */
g : 문자열 내에 모든 패턴을 검색 ( 전체 )
i : 대소문자를 구별하지 않고 검색
/Hello/gi : 대소문자 구별없이 문자열을 검색한다.
문자열 변수 정규식 사용
let string = "Hello word Hello word Hello word";
let reString = "hello";
let regex = new RegExp(reString, "gi");
string = string.replace(regex, "");
정규식을 사용하기 위한 객체를 만들어 사용한다.
'프로그래밍 언어 > JavaScript' 카테고리의 다른 글
| HTML 요소 선택 JS 함수 정리 (0) | 2023.12.31 |
|---|---|
| Form submit 기본흐름 제어 (0) | 2023.11.11 |
| onfocus, onblur 이벤트 (0) | 2023.09.22 |
| JavaScript 이미지 규격 체크 onload 함수 (0) | 2023.03.13 |
| XMLHttpRequest / jQuery 데이터 요청, 응답 (0) | 2023.01.10 |
Comments