|
var data = "%7B%22user%22:%22bfce3822-d2ce-4327-a813-00e616f4773b%22,%22consents" + |
|
"%22:%5B%22undefined%22,%22necessary%22,%22statistical%22%5D,%22avail" + |
|
"ableConsents%22:%5B%22undefined%22,%22necessary%22,%22marketing%22,%" + |
|
"22statistical%22%5D,%22utc%22:1697017078669%7D" |
|
|
|
//////////////////// |
|
// Match using regex |
|
//////////////////// |
|
var altStatistical1 = /%22consents%22:.*statistical.*%22availableConsents%22/ |
|
var altStatistical2 = /\%22consents\%22:.*statistical.*\%22availableConsents\%22/ |
|
var altStatistical3 = /.22consents.22:.*statistical.*.22availableConsents.22/ |
|
var altStatistical4 = /...consents...:.*statistical.*...availableConsents.../ |
|
|
|
console.log(altStatistical1.test(data)) |
|
console.log(altStatistical2.test(data)) |
|
console.log(altStatistical3.test(data)) |
|
console.log(altStatistical4.test(data)) |
|
|
|
|
|
var altMarketing1 = /%22consents%22:.*marketing.*%22availableConsents%22/ |
|
var altMarketing2 = /\%22consents\%22:.*marketing.*\%22availableConsents\%22/ |
|
var altMarketing3 = /.22consents.22:.*marketing.*.22availableConsents.22/ |
|
var altMarketing4 = /...consents...:.*marketing.*...availableConsents.../ |
|
|
|
console.log(altMarketing1.test(data)) |
|
console.log(altMarketing2.test(data)) |
|
console.log(altMarketing3.test(data)) |
|
console.log(altMarketing4.test(data)) |
|
|
|
//////////////////// |
|
// March using js |
|
//////////////////// |
|
var dataJson = decodeURI(data) |
|
var dataObj = JSON.parse(dataJson) |
|
|
|
|
|
// Should return true |
|
console.log(dataObj.consents.includes("statistical")) |
|
|
|
// Should return false |
|
console.log(dataObj.consents.includes("marketing")) |
|
|