Skip to content

[SOLVED] Two JavaScript newbie questions for article filtering (whole words / case-sensitivity) #1264

Answered by martinrotter
PMTabs asked this question in Q&A
Discussion options

You must be logged in to vote

Hi.

  1. Yes, you have to use "\b" word boundary syntax. Check below example for better understanding.
  2. Yes, it is possible with "i" modifier, see below example, example will only match "XXYY" or "xxyy" as separate words.
const regex = /\bXXYY\b/i;

function filterMessage() {
  if (regex.test(msg.title)) {
    // matched!!!
  }

  return MessageObject.Accept;
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@PMTabs
Comment options

@martinrotter
Comment options

Answer selected by PMTabs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants