im пытается написать регулярное выражение для поиска и замены пути изображения и сохранения того же имени файла существующего пути к пути удаленного сервера.Coldfusion при загрузке замены пути к изображениям REGEX
пользователь загружает HTML-файл, который я хочу, загружая путь замены перед сохранением в db.
Я написал некоторое Regex, похоже, не работает, я не очень хорошо в regex, который я нашел в Интернете.
Вы найдете ниже фрагмент кода ...
for example this my HTML content.
<cfsavecontent variable="htmlcont">
<html>
<head>
</head>
<body>
<a href='http://www.w3schools.com'><img src='http://www.w3schools.com/images/w3schools.png' alt='W3Schools.com' class='img-responsive'></a>
<div class="w3-row">
<div class="w3-third w3-center">
<h2>JPG Images</h2>
<img alt="Mountain View" src="pic_mountain.jpg" style="width: 304px; height: auto" class="img-responsive">
</div>
<div class="w3-third w3-center">
<h2>GIF Images</h2>
<img alt="" src="html5.gif" style="width: 128px; height: auto" class="img-responsive">
</div>
<div class="w3-third w3-center">
<h2>PNG Images</h2>
<img alt="Graph" src="pic_graph.png" style="width: 170px; height: auto" class="img-responsive">
</div>
</div>
<table class="lamp"><tr>
<th style="width:34px">
<img src="/images/lamp.jpg" alt="Note" style="height:32px;width:32px"></th>
<td>Always specify the width and height of an image. If width and height are not specified, the page will flicker while the image loads.
</td>
</tr></table>
<hr>
<table class="lamp"><tr>
<th style="width:34px">
<img src="/images/lamp.jpg" alt="Note" style="height:32px;width:32px"></th>
<td>Add "border:0;" to prevent IE9 (and earlier) from displaying a border around the image.</td>
</tr></table>
<hr>
</body>
</html>
</cfsavecontent>
им пытаются заменить
http://www.w3schools.com/images/w3schools.png
К
http://myremoteServer.com/234001/images/w3schools.png
ИЛИ
<img alt="Graph" src="pic_graph.png" style="width: 170px; height: auto" class="img-responsive">
К
<img alt="Graph" src="http://myremoteServer.com/234001/images/pic_graph.png" style="width: 170px; height: auto" class="img-responsive">
КОД:
<cfset regxv = 'src="\K[^"]*(?=")' />
<cfset resluthtml = REReplace (htmlcont,regxv, "http://myremoteServer.com/234001/images/") />
<cfdump var="#resluthtml#" label="resluthtml" >
Пожалуйста, используйте jSoup вместо Regex. См: http://www.bennadel.com/blog/2358-parsing-traversing-and-mutating-html-with-coldfusion-and-jsoup.htm – Henry