Skip to content

Instantly share code, notes, and snippets.

@bethropolis
Last active March 7, 2024 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bethropolis/8a246c9f4216b0626ffeae7f2de1403a to your computer and use it in GitHub Desktop.
Save bethropolis/8a246c9f4216b0626ffeae7f2de1403a to your computer and use it in GitHub Desktop.
judul ishura
// HTML snippet
const htmlSnippet = `
<div class="infozingle">
<p>
<span>
<b>Judul</b>: Ishura
</span>
</p>
</div>
`;
// REGEX
const regexPattern = /<b>(.*?)<\/b>:\s*(.*)/;
const matches = htmlSnippet.match(regexPattern);
if (matches) {
const fullName = matches[1] + " " + matches[2];
console.log(fullName);
} else {
console.log("No match found.");
}
// USING DOM
const parser = new DOMParser();
const doc = parser.parseFromString(htmlSnippet, 'text/html');
const spanText = doc.querySelector('.infozingle span').textContent.trim();
console.log(spanText);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment