DWard
DWard

Reputation: 119

Javascript regex to check for at least 3 carets in a string

I am requesting assistance with a regular expression to show that there are at least 3 carets in a string. I've tried using /\^/ but that only finds if the caret exists one time.

Example Data:

KEYWORD^HOSTNAME^MESSAGE^NUMBERS

Upvotes: 1

Views: 79

Answers (1)

Emeeus
Emeeus

Reputation: 5260

This expression should work:

(.*\^.*){3}

Example in javascript:

var str = "KEYWORD^HOSTNAME^MESSAGE^NUMBERS";
var patt = new RegExp(/(.*\^.*){3}/);
var res = patt.test(str);
console.log(res);

Upvotes: 2

Related Questions