Reputation: 43
I'm debugging someone's code and wondering what this regex does?
Code:
<script>
var t = document.getElementById("filterVal").value;
var s = filterVal.replace(/"([^"]+(?="))"/g, '$1')
</script>
Upvotes: 2
Views: 64
Reputation: 386570
It removes a balanced count of double quotes.
console.log('a"bc"de"f'.replace(/"([^"]+)(?=")"/g, '$1'));
console.log('a"bc"d"e"f'.replace(/"([^"]+)(?=")"/g, '$1'));
// a version without a positive lookahead (looks like the same result)
console.log('a"bc"de"f'.replace(/"([^"]+)"/g, '$1'));
console.log('a"bc"d"e"f'.replace(/"([^"]+)"/g, '$1'));
Upvotes: 4
Reputation: 1014
As stated basically removes the qoutes: say filteVal = "It's sunny today"
var t = document.getElementById("filterVal").value;
var s = filterVal.replace(/"([^"]+(?="))"/g, '$1')
//output: It's sunny today
You can also try it out by just right clicking in chrome and opening inspect and typing it out in the console.
Upvotes: 1