diff --git a/Specialized Areas/Regular Expressions/Hashtag & Mention Extractor/README.md b/Specialized Areas/Regular Expressions/Hashtag & Mention Extractor/README.md new file mode 100644 index 0000000000..86987c0ad3 --- /dev/null +++ b/Specialized Areas/Regular Expressions/Hashtag & Mention Extractor/README.md @@ -0,0 +1,35 @@ +# Hashtag & Mention Extractor for ServiceNow + +A simple yet useful **ServiceNow Background Script** that extracts all hashtags (`#example`) and mentions (`@user`) from any text input using regular expressions. + +This script demonstrates how to apply JavaScript RegEx in server-side ServiceNow logic to parse, analyze, or extend user-generated text - ideal for text-analysis demos or lightweight automation projects. + +--- + +## πŸ’‘ Example Use Cases +- Automatically identify hashtags and mentions in **incident comments**, **knowledge articles**, or **survey feedback**. +- Build internal analytics to track trending topics like `#VPN`, `#email`, or `#network`. + +--- +## πŸš€ How to Run +1. In your ServiceNow instance, navigate to **System Definition β†’ Scripts – Background**. +2. Paste the script from this repository. +3. Click **Run Script**. + +--- + +## πŸ“¦ Reusability +The logic is **self-contained** within a single function block β€” no dependencies or external calls. +You can easily **copy and adjust it** to fit different contexts: +- Use it inside a **Business Rule**, **Script Include**, or **Flow Action Script**. +- Replace the sample `demoData` with a field value (e.g., `current.comments`) to analyze live data. +- Adjust the regex to detect other patterns (emails, keywords, etc.). + +This makes it a **plug-and-play snippet** for any ServiceNow application or table that requires quick text pattern recognition. + +--- + +## πŸ”§ Possible Extensions +- Parse live table data (`sys_journal_field`, `kb_knowledge`) instead of static text. +- Store extracted tags in a custom table for analytics. +- Schedule a nightly β€œTop Tags” report with **Flow Designer** or **PA Widgets**. diff --git a/Specialized Areas/Regular Expressions/Hashtag & Mention Extractor/script.js b/Specialized Areas/Regular Expressions/Hashtag & Mention Extractor/script.js new file mode 100644 index 0000000000..6e4eb7cbba --- /dev/null +++ b/Specialized Areas/Regular Expressions/Hashtag & Mention Extractor/script.js @@ -0,0 +1,15 @@ +(function() { + + var demoData = "Quick test for hashtag and mention extraction in ServiceNow. " + + "Let's make sure it catches #Hack4Good #ServiceNow #regex and mentions like @ivan and @servicenow."; + + var tagRegex = /[#@][A-Za-z0-9_]+/g; + var matches = demoData.match(tagRegex); + + if (matches && matches.length > 0) { + gs.info('Found ' + matches.length + ' tags: ' + matches.join(', ')); + } else { + gs.info('No hashtags or mentions found.'); + } + +})();