Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascrip split function unusual delimiters

Status
Not open for further replies.

fwclough

Programmer
Nov 24, 2008
3
I have a javascript function that receives the following string:

<p><img src="picts/Gay_FT_lg.jpg" border="0" alt="" /></p>

I want to use the temp1.split() function to extract the name of the file(i.e., picts/Gay_FT_lg.jpg).

I thought it would be simpliest to split the string using a double quote as the delimiter. However I am unable to figure out how to do this.

Any help would be appreciated.
 
It's all to do with how you use the quote marks...

Code:
...
var temp1 = '<p><img src="picts/Gay_FT_lg.jpg" border="0" alt="" /></p>';
var split1 = temp1.split('[!]"[/!]');
alert(split1[1]);
...

Cheers,
Jeff

[tt]Visit my blog [!]@[/!] Visit Code Couch [!]@[/!] [/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Thank you soooo much. It was right in front of my nose and I still didn't see it.

Thank you again.
 
Hi

And what if the [tt]src[/tt] attribute is not the first ? I would say better do not rely on [tt]split()[/tt].
Code:
/src="(.*?)"/i.exec(temp1)[1]

[gray]# or the same somehow more readable[/gray]

new RegExp('src="(.*?)"','i').exec(temp1)[1]

Feherke.
 
Feherke:

Thank you. I agree with your caution.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top