# include와 정규식

지난번에 input에 공백을 검사했었는데 이메일 형식을 검사해보자.

```javascript
'문자'.includes('찾을단어');
```

이렇게 하면 입력된 값에 원하는 문자가 있는지 찾아준다.

있다면 true 없다면 false 반환&#x20;

하지만&#x20;

-한글이 있는지?

-영어가 있는지?

-특정 단어로 끝나는지?

-@ 다음에 영어가 있는지?

이런것은 includes()만으로 검사하기 어렵다.

## 정규표현식(regular expression)

정규표현식은 문자를 검사하고 싶을 때 사용하는 식

어떤 문자에 'naver'라는 단어가 들어가 있냐 확인하고 싶을 때 이렇게  쓴다.

```javascript
/naver/.test('id@naver.com');
```

```javascript
// 영어 정규표현식
/[a-zA-Z]/.test('영어가 있는지 확인해줘');
// 한글 정규표현식
/[ㄱ-ㅎ가-힣ㅏ-ㅣ]/.test('한글이 있는지 확인해줘');
```

<figure><img src="/files/oxtw5mXeR5UGXuoyG4c7" alt=""><figcaption><p>정규표현식 문법</p></figcaption></figure>

{% embed url="<https://rubular.com/>" %}
정규표현식 테스트 사이트&#x20;
{% endembed %}

하지만 우리가 정규표현식을 처음부터 다 짠다는 것은 비효율적이다.

구글 선생님은 모든 것을 알고 있다.

```javascript
//이메일 정규식
/[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]$/i


//이메일 정규식 업그레이드 (특수문자중 . - _ 가능)
/^([\w\.\_\-])*[a-zA-Z0-9]+([\w\.\_\-])*([a-zA-Z0-9])+([\w\.\_\-])+@([a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,8}$/i


//정규식을 적용해보자
var regExp = /^([\w\.\_\-])*[a-zA-Z0-9]+([\w\.\_\-])*([a-zA-Z0-9])+([\w\.\_\-])+@([a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,8}$/i;

if(!regExp.test($('#email').val())){
  alert("이메일 형식을 확인하세요");
  e.preventDefault();
}
```

내가 계속 구글에 검색하고 그 결과를 보여주는 이유?

단순히 정제된 지식 정리된 자료만 가지고 배우다 보면

실제로 업무에서 난관에 부딪혔을 때&#x20;

어 ? 나 배운적 없는건데 근데 어떻게 해결하지? 이렇게 되버린다.

구글 , stackoverflow , okky 등 다양한 곳에서 검색하고&#x20;

그걸 내 코드에 적용하는 것도 실력이다.

심지어 ChatGPT도 마찬가지다.&#x20;

좋은 자료를 검색하고 단순 복붙이 아니라 내 코드에 잘 적용하는 것이 실력이다.&#x20;

{% embed url="<https://survey.stackoverflow.co/2023/>" %}
Stackoverflow 설문조사 결과
{% endembed %}

{% embed url="<https://stackoverflow.co/labs/developer-sentiment-ai-ml/#h2-f23f00df4dec0>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://leeans-dev-book.gitbook.io/docs/lecture/javascript/include.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
