패턴과 일치하는 자바 스크립트의 문자열에서 하위 문자열을 어떻게 얻을 수 있습니까? 이 문자열이 있습니다.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</head>
<body bgcolor="#efefef"
style="background: #efefef; margin: 0; padding: 0; width: 100%; -webkit-font-smoothing: antialiased; font-family: 'Roboto', sans-serif; font-weight: 400;">
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="width: 600px; margin: 0 auto; padding: 0;">
<tbody>
<tr>
<td width="100%">
<table width="100%" cellspacing="0" cellpadding="0" border="0"
style="width: 600px; margin: 0 auto; padding: 20px 0 12px 0;">
<tbody>
<tr>
<td width="50%">Webmail App
</td>
<td width="50%">
<div style="color: #5d5d5d; font-size: 14px; font-weight: bold; letter-spacing: 1px; font-family: 'Helvetica Neue',Arial,Helvetica,sans-serif; text-align: right;">
{{current_date}}
</div>
</td>
</tr>
</tbody>
</table>
<div style="width: 600px; margin: 0 auto; border: 1px solid #CCCCCC; background-color: #FFFFFF;">
<div style="background-color: #0065b2; color: #fbfbfb; font-size: 18px; font-weight: bold; padding: 16px 12px 16px 12px; font-family: 'Helvetica Neue',Arial,Helvetica,sans-serif;">
Application for {{application_position}}
</div>
<div style="background-color: #4676fd; color: #efefef; font-size: 16px; font-weight: bold; letter-spacing: 1px; padding: 16px 12px; border-bottom: 1px solid #CCCCCC; font-family: 'Helvetica Neue',Arial,Helvetica,sans-serif;">
{{applicant_name}}
</div>
<div style="background-color: #fffff; color: #0E2334; font-size: 18px; font-weight: bold; padding: 24px 12px 8px 12px; font-family: 'Helvetica Neue',Arial,Helvetica,sans-serif;">
this is a sample message.
</div>
<div style="background-color: #fffff; color: #0E2334; text-align: left;">
</div>
<div style="background-color: #fffff; color: #0E2334; text-align: left; padding: 24px 12px 8px 12px; font-size: 13px; font-family: 'Helvetica Neue',Arial,Helvetica,sans-serif; letter-spacing: 0.5px;">
Thanks,<br/>{{staff_name}}</div>
</div>
<div style="width: 600px; margin: 0 auto; padding: 0 0 20px 0;"><p
style="color: #666; font-size: 11px; letter-spacing: 0.5px; font-weight: 500; text-decoration: none; font-family: 'Helvetica Neue',Arial,Helvetica,sans-serif;">
Thank you for using Webmail<br/> </div>
</td>
</tr>
</tbody>
</table>
</body>
</html>
이것은 문자열입니다. 이메일 템플릿에서 사용했습니다. 일치하는 모든 하위 문자열을 어떻게 얻을 수 있습니까?
{{something_code}}
따라서 출력은 다음 값을 가진 배열이어야합니다.
["current_date","application_position","applicant_name","staff_name"]
이러한 값은 동적입니다. 얼마나 많은 특수 코드가 있는지는 템플릿에 따라 다릅니다.
또한 값은 고유해야합니다.
필터 기능을 시도했지만 작동하지 않습니다. 내가 어떻게 해? 자바 스크립트로 할 샘플이 있습니까?
문자열에 다음과 같은 변수가 있다고 가정합니다. html_str
var results = html_str.match(/[^{{}}]+(?=\})/g);
results
배열이됩니다. 따라서 귀하 results
가 게시 한 html의 경우["current_date","application_position","applicant_name","staff_name"]
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다