Skip to content

Instantly share code, notes, and snippets.

@josefaidt
Created December 5, 2022 18:49
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 josefaidt/6e46c0e671c54317c51f4d889f716a67 to your computer and use it in GitHub Desktop.
Save josefaidt/6e46c0e671c54317c51f4d889f716a67 to your computer and use it in GitHub Desktop.
const regex = /<(?<tag>[^>]*)>/;
/**
* Verifies whether the string is an HTML string
* @param str string to check
*/
export const isHtmlString = (str: string): boolean => {
// <code>hello world</code> -> true
// hello <code>world</code> -> true
// hello world -> false
return regex.test(str);
};
/**
* Verifies whether the string is an HTML inline code block string
* @param str string to check
*/
export const isHtmlCodeTagString = (str: string): boolean => {
const result = regex.exec(str);
return result?.groups?.tag === 'code';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment