Hi guys
I have a string (read from a text file), and i need to be able to pull out the value in the quotation marks. For example:

if my string is <img src="hello.jpg">

, I need to return hello.jpg.

The tough part is that there can by any number of spaces (including 0) in between img and src, between src and = , and between = and the first quotation mark.

Do I need to use wildcards?

That was hard to describe... hope someone understood my problem.

10 Years
Discussion Span
Last Post by campkev

Your best bet would be to use the regular expression object to find matches to the pattern you want. An example script is included below.

dim sampletext, objRegExp, SearchPattern, ReplacePattern, matches

sampletext = "<img src=""hello.jpg"">"

'// enter the search pattern here
SearchPattern = """" ' opening quote
SearchPattern = SearchPattern & "(.*?)" ' any number of text characters
SearchPattern = SearchPattern & """" ' closing quote

'// create a new instance of the regular expression object
Set objRegExp = New RegExp

objRegExp.Pattern = searchpattern ' apply the search pattern
objRegExp.Global = True ' match all instances if the serach pattern
objRegExp.IgnoreCase = True ' ignore case

'// find all occurences of the search pattern in the sample text
Set matches = objRegExp.execute(sampletext)

If matches.Count > 0 Then ' there was at least one match to the search pattern
  For Each match in matches
    Response.Write replace(match.Value, """", "") & "<br>"
Else ' there were no matches found
  Response.Write "<B>" & objRegExp.Pattern & "</B> was not found in the string: <B>" & StringToSearch & "</B>."
End If

'// releast the reg exp object
Set objRegExp = nothing

if you know that it should always be only two question marks, here is something a little easier


inputString = "<img src=""hello.jpg"">"
inputString = Replace(inputString, """", Chr(0))

strArray = Split(inputString,Chr(0))

if ubound(strArray) = 2 then
 resultString = response.write strArray(1)
 ' psuedocode 
 ' something went wrong, so handle problem
end if

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.