Say I have this string:
["teads.tv, 15429, reseller, 15a9c44f6d26cbe1 ","video.unrulymedia.com,367782854,reseller","google.com, pub-8173359565788166, direct, f08c47fec0942fa0","google.com, pub-8804303781641925, reseller, f08c47fec0942fa0 "]
I am trying to extract all the text strings like teads.tv, google.com and etc. Each text string is placed in the following way "text.text,, but there are aslo combinations of ", without any character in between.
I tried this Regex expression:
"(.*?)\,
but I also capture the empty combinations, you can check it out here.
How can I modify the Regex expression, so it would capture only the combination with a string between ",?
Cheers,
CodePudding user response:
How about using
(one or more) instead of *
(zero or more) as quantifier:
"(. ?),
Additionally, you may not need to escape ,
with backslash.
CodePudding user response:
If there should be at least a single non whitespace char present other than "
,
[
]
you can match optional whitespace chars and use a negated character class listing all the characters that should not be matched and repeat that 1 or more times.
"(\s*[^\][\s",] ),
The more broad variation is to repeat 1 times any char except a comma:
"([^,] ),
CodePudding user response:
Reading the question as retrieving the string with a dotted notation such as domain names means that we are looking for the first string after a "
.
This string will grab strings with dots within them, but avoid the quote characters.
const regEx = /(?:\")([\w\d\.\-] )/g;
const input = '["teads.tv, 15429, reseller, 15a9c44f6d26cbe1 ","video.unrulymedia.com,367782854,reseller","google.com, pub-8173359565788166, direct, f08c47fec0942fa0","google.com, pub-8804303781641925, reseller, f08c47fec0942fa0 "]';
const regMatch = Array.from(input.matchAll(regEx), m => m[1]);
console.log(regMatch)
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>