Skip to content

Instantly share code, notes, and snippets.

@CMarzin
Last active August 30, 2017 10:53
Show Gist options
  • Save CMarzin/48bcd60b5c4109b218513f7a4c442fb1 to your computer and use it in GitHub Desktop.
Save CMarzin/48bcd60b5c4109b218513f7a4c442fb1 to your computer and use it in GitHub Desktop.
Regex for terms and conditions
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>regex terms and conditions</title>
</head>
<body></body>
<script>
var regex = /.*./g;
var str = `Copy paste here you terms and conditions directly from word/whatever`;
var m;
var arrayMatchToDisplay = [];
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
m.forEach((match, groupIndex) => {
var regexMatch = `<p>&lt;p&gt;${match}&lt;/p&gt;</p>`;
arrayMatchToDisplay.push(regexMatch);
});
}
document.body.innerHTML = arrayMatchToDisplay.join('')
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment