Question

EDIT: THIS POST IS FIXED, READ MORE DOWN FOR MORE HELP

I have this diferents regular expressions:

var rex=new RegExp('<img.*?src="(.*?\/([^/"]*))".*?>', 'g')
var rex=new RegExp('<img [^>]*src="([^>"]+\/([^>"]+))"[^>]*?>', 'g')
var rex=new RegExp('<img.*?src="([^">]*\/([^">]*?))".*?>', 'g') 

SOLUTION:

After  : <img [^>]*src="([^>"]+\\/([^>"]+))"[^>]*?>  
After  : <img.*?src="(.*?\\/([^\/"]*))".*?>
After  : <img.*?src="([^">]*\\/([^">]*?))".*?>

SOLUTION:

When i declare the url the string no detect the "\" because no is escaped

And this URL ( for example):

var str = '<img src="file:///C:\DOCUME~1\user\CONFIG~1\Temp\msohtml1\02\clip_image002.jpg" style="float:left; height:145px; width:193px" />';

BUT when i declare the "str" no have the "\", how i can resolve that? i can't manual because this strings come automatic.

I use this while for push the URL in a array

var m,urls = [];
    while ( m = rex.exec( str ) ) {
            urls.push( m[1] );
        }
            alert( urls ); 

i use all the regulars expressions but they return all time the same text:

file:///C:DOCUME~1cCanadasCONFIG~1Tempmsohtml1clip_image002.jpg

I know it's because the regular expression not detect the backslash, but i don't know where or how can i write the regular expression for that.

SECOND PROBLEM

EXAMPLE: I have this text in one string:

Blockquote

<img src="file:///C:\DOCUME~1\cCanadas\CONFIG~1\Temp\msohtml1\01\clip_image002.jpg" style="float:left; height:145px; width:193px"></a></a><img src="file:///C:\DOCUME~1\cCanadas\CONFIG~1\Temp\msohtml1\01\clip_image004.jpg" style="float:left; height:192px; width:256px">Ut elementum tempor quam, vel accumsan quam interdum nec. Quisque porta urna convallis, posuere diam in, sodales quam. Mauris ligula magna, sollicitudin id egestas at, pharetra eget erat. Quisque dignissim libero in lectus vestibulum commodo. Nunc vel augue augue. Sed vel magna egestas, laoreet nulla nec, aliquet velit. Quisque augue quam, eleifend non sollicitudin sit amet, vestibulum a nulla. Fusce pulvinar diam dapibus nunc posuere, at

How I can detect the SRC of IMG and change your backslashes by forward slashes?

Would appreciate your help! Thank you very much!

P.d: If you can write the answer in JavaScript, but if you know other no problem for me-

Was it helpful?

Solution

You just need to escape the \ characters:

Before : <img [^>]*src="([^>"]+\/([^>"]+))"[^>]*?>
After  : <img [^>]*src="([^>"]+\\/([^>"]+))"[^>]*?>

Before : <img.*?src="(.*?\/([^/"]*))".*?>
After  : <img.*?src="(.*?\\/([^\/"]*))".*?>

Before : <img.*?src="([^">]*\/([^">]*?))".*?>
After  : <img.*?src="([^">]*\\/([^">]*?))".*?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top