1

How do I extract 'inc/funcs.asp' from the string below, with Jquery or Javascript.

<script>
 var str = '<!-- #include file="inc/funcs.asp" -->';  
</script>

I imagine the pattern must start with looking for '#include file="'

3 Answers 3

2

You can use this regex:

/file="([^"]+)/

and grab captured group #1

Code:

var fval = (str.match(/file="([^"]+)/) || ['', ''])[1];
Sign up to request clarification or add additional context in comments.

1 Comment

Interesting, I see your logic, by grabbing out what's between the double quotes. I was originally going for a more complicated approach.
2

var text = '<!-- #include file="inc/funcs.asp" -->';
var str = text.match(/"(.*?)"/);
alert(str[1]);

Comments

0
var str = '<!-- #include file="inc/funcs.asp" -->';  
str.match(/\"(.+)\"/)[1];

returns "inc/funcs.asp"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.