I submitted this Extract String RegEx Question post not too long ago.
I want to enhance the expression pattern more.
So far this works nicely:
<script>
// extract the inc/funcs.asp from the variable.
var text = '<!-- #include file="inc/funcs.asp" -->';
var pattern = /file="([^"]+)/i
var result = (text.match(pattern) || ['', ''])[1];
console.log(result); // returns: inc/funcs.asp
</script>
I'm now testing white-space nuances. The pattern I'm applying is: /file="([^"]+)/i I'd like to add more to this pattern.
For example:
var pattern = /#include file="([^"]+)/i
And this works, unless there's more space between the #include and file.
So I altered the pattern to this:
var pattern = /#include(\s+)file="([^"]+)/i
Full Script:
<script>
var text = '<!-- #Include File="inc/funcs.asp" -->';
var pattern = /#include(\s+)file="([^"]+)/i
var result = (text.match(pattern) || ['', ''])[1];
var count = result.length;
if(count > 0){
console.log(result);
}
</script>
The count variable is greater than 0, and runs the console.log.
But the variable result is empty.
What I'm missing?