首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >MYSQL替换两个已知字符串之间的字符串

MYSQL替换两个已知字符串之间的字符串
EN

Stack Overflow用户
提问于 2014-05-18 19:57:53
回答 3查看 4.7K关注 0票数 2

编辑1:我正在尝试使用下面的查询来获取,但问题是end div不是在开始点之后出现的,即

代码语言:javascript
运行
复制
select ID, post_title, substr(post_content,instr(post_content,'<div style="position:absolute') + 0, instr(post_content,'</div>')) as temp from wp_posts where post_content LIKE '%mySpamFilter Text%' LIMIT 10

我的一个博客受到了垃圾邮件发送者的攻击,我在100+上发布了一些不想要的链接或信息,这些链接或消息被垃圾邮件者所融合。我想知道如何替换两个字符串之间的字符串。

代码语言:javascript
运行
复制
Start string = '<div style="position:absolute;'
End String = '</div>'  (This End div should be the first end div after the above Start string)

我尝试了所有的选项,这是可用的堆栈溢出,但至今没有运气。请给我们建议什么是最好的方法。下面是post_content列的内容,来自wp_posts表中的一篇文章,您可以看到在单词Paneer之后,div类之间有大量垃圾邮件。我想把这个从我的数据库里处理掉。我不知道我是如何成为这次袭击的受害者,但现在我只想删除这些。

代码语言:javascript
运行
复制
 <p>Hey Foodies,</p>
<p>Biryani, the pride of Hyderabad, is definitely one dish which everyone knows to cook in their very own ways and styles. Biryani is one such thing which totally distinguishes itself with the plain rice we eat daily and the regular pulao. Biryani is the BIRYANI. So, lets look into the detailed procedure of the much loved Hyderabadi delicacy, the vegetarian version. Oh yes, this is the Hyderabadi Dum Veg Biryani!</p>
<p>This recipe would take 380-400 grams of uncooked Basmati rice which would serve 6.</p>
<div class="easyrecipe">
<link itemprop="image" href="http://mywebsite.in/wp-content/uploads/2013/09/Biryani-300x225.jpg">
<div class="item ERName">Hyderabadi Veg Dum Biryani</div>
<div class="ERClear"></div>
<div class="ERHead"><span class="xlate">Recipe Type</span>: <span class="type">Main Course</span></div>
<div class="ERHead">Cuisine: <span class="cuisine">Indian</span></div>
<div class="ERHead">Prep time: <time itemprop="prepTime" datetime="PT30M">30 mins</time></div>
<div class="ERHead">Cook time: <time itemprop="cookTime" datetime="PT1H15M">1 hour 15 mins</time></div>
<div class="ERHead">Total time: <time itemprop="totalTime" datetime="PT1H45M">1 hour 45 mins</time></div>
<div class="ERHead">Serves: <span class="yield">6</span></div>
<div class="ERIngredients">
<div class="ERIngredientsHeader">Ingredients</div>
<ul class="ingredients">
<li class="ingredient">For Vegetables: Carrot - 1 medium</li>
<li class="ingredient">Potatoes - 1 medium</li>
<li class="ingredient">Paneer ***<div style="position:absolute; left:-3905px; top:-3984px;">Gloves fast it <a href="http://www.goprorestoration.com/natural-viagra-foods">natural viagra foods</a> recently! Like as <a href="http://www.backrentals.com/shap/daily-cialis.html">daily cialis</a> the purchase 1 pad <a href="http://www.vermontvocals.org/buy-online-cialis.php">generic viagra cheap</a> and matte easy <a href="http://www.teddyromano.com/blue-pills/">blue pills</a> me many. Content but <a href="http://augustasapartments.com/qhio/10-mg-cialis">10 mg cialis</a> the as the helps Amazon <a href="http://www.mordellgardens.com/saha/cheap-viagra-canada.html">http://www.mordellgardens.com/saha/cheap-viagra-canada.html</a> . And baths etc would. I've <a href="http://www.teddyromano.com/brand-cialis/">brand cialis</a> Appears dollars hands still <a href="http://www.backrentals.com/shap/generic-cialis-europe.html">shop</a> October a smell <a href="http://www.hilobereans.com/buy-real-viagra/">http://www.hilobereans.com/buy-real-viagra/</a> in have. Of better <a href="http://www.creativetours-morocco.com/fers/herbal-viagra-australia.html">cheap generic cialis</a> it smelled to and <a rel="nofollow" href="http://www.goprorestoration.com/best-price-viagra">best price viagra</a> t customer anything been <a href="http://www.mordellgardens.com/saha/viagra-online-reviews.html">viagra online reviews</a> 5 supply time <a href="http://www.hilobereans.com/viagra-canada-pharmacy/">"here"</a> the product what <a href="http://www.vermontvocals.org/ed-supplements.php">buy levitra</a> biological by cream!</div>***  - 1/2 cup</li>
<li class="ingredient">Cauliflower - 1/2 cup</li>
<li class="ingredient">Green peas - 1 tbsp.</li>
<li class="ingredient">Yogurt - 1/2 cup</li>
<li class="ingredient">Mint - 1 tbsp.</li>
<li class="ingredient">Coriander - 1 tbsp.</li>
<li class="ingredient">Ginger-Garlic paste - 1 tsp.</li>
<li class="ingredient">Green chili - 4 to 5</li>
<li class="ingredient">Oil - 2 tbsp</li>
<li class="ingredient">Salt - As per taste</li>
<li class="ingredient">Biryani Masala - 1 and 1/2 tbsp.</li>
<li class="ingredient">Red Chili Powder - 1/2 tsp.</li>
<li class="ingredient">Garam Masala Powder - 1/4 tsp.</li>
<li class="ingredient">Whole Garam Masala - Custom or readymade</li>
<li class="ingredient">For Rice: Basmati Rice(soaked for 1 hour) - 380 gms</li>
<li class="ingredient">Water - 6-8 cups</li>
<li class="ingredient">Oil - 1-2 Tbsp.</li>
<li class="ingredient">Whole Garam masala - Custom or readymade</li>
<li class="ingredient">Salt - 3 Tsp.</li>
<li class="ingredient">For Dum(Bringing together): Yogurt - 1/2 cup</li>
<li class="ingredient">Saffron strands - dipped in milk, a few</li>
<li class="ingredient">Chopped Nuts - As desired</li>
<li class="ingredient">Mint and Coriander - two handfuls</li>
<li class="ingredient">Fried onions - two handfuls</li>
<li class="ingredient">Green chili - 4-5 slits</li>
<li class="ingredient">Water - 1/4 cup</li>
</ul>
</div>
<div class="ERInstructions">
<div class="ERInstructionsHeader">Instructions</div>
<div class="instructions">
<ol>
<li class="instruction">For Veggies: In a kadhai add oil. Now add whole garam masala, ginger-garlic paste. Saute for a minute. Now add carrot, potatoes, cauliflower, peas and salt. Saute until they are lightly cooked.</li>
<li class="instruction">After the veggies are a bit cooked, add in biryani masala, red chili powder, garam masala powder and gradually add yogurt stirring well to prevent curdling of curd.</li>
<li class="instruction">Now add mint, coriander, paneer. Cook until the moisture gets dried out which was caused due to adding yogurt. This would take approx 5 minutes. Veggies should not be cooked completely as we will dum it later on. It should 70% cooked.</li>
<li class="instruction">After the moisture is dried, add some fried onions and transfer to a bowl.</li>
<li class="instruction">For Rice: Boil water. Add oil, whole garam masala, salt. Boil until roaring boil. Add the soaked rice. In about 3-4 minutes in high flame rice will be 70% done. Test by eating some if it has a bite but its tastes like cooked or press between ur fingers. If breaks into 2 parts its ready. Strain it and spread on a big plate.</li>
<li class="instruction">For Dum: Take a cooker, add half of the vegetables, yogurt, green chilli, a pinch of salt and some nuts. Let it heat. Now add a handful of mint coriander. Now top it off with a good layer of rice.</li>
<li class="instruction">Next add the remaining vegetables, remaining mint-coriander(leave 1 tsp. for top), fried onions and the rice. Spread the rice and add the saffron mixture with a bit of mint-coriander, fried onion.</li>
<li class="instruction">Now sprinkle 1/4 cup of water over it, Cover and cook for 2 minutes in lowest flame.</li>
<li class="instruction">Transfer the cooker to a big pot with some water. This water bath prevents the dum to get burnt.. In about 30-35 minutes the Biryani is ready to make you dig into it.</li>
</ol>
</div>
</div>
<div class="ERNutrition"></div>
<div>
<div class="ERNotesHeader">Notes</div>
<div class="ERNotes">Cut vegetables in a uniform size.[br]Veggies are less, but the rice is used more for Biryanis.[br]You could use raw chopped nuts or saute them in oil and add.[br]Make sure to soak rice for atleast 1 hour.</div>
</div>
<div class="endeasyrecipe" style="display: none;">3.2.1255</div>
</div>
<p>&nbsp;</p>
<p><a href="http://mywebsite.in.cp-25.webhostbox.net/wp-content/uploads/2013/09/Biryani-2.jpg"><img class=" wp-image-411 alignright" alt="Biryani-2" src="http://mywebsite.in.cp-25.webhostbox.net/wp-content/uploads/2013/09/Biryani-2.jpg" width="189" height="142"></a></p>
<p>Recipe Ingredients are lengthy.. But it looks only onscreen.. Once you start preparing them they does not seem long or more.. Basic Ingredients, Easy Recipe and Traditional Hyderabadi Taste.. Dont forget to try it, I am sure you'll love it and make it again and again!!!</p>
<p><a href="http://www.youtube.com/mywebsite" target="_blank">Do Subscribe on YouTube</a></p>
<p><a href="http://www.fb.com/mywebsite" target="_blank">Like us on FB</a></p>
<p>&nbsp;</p>
<p>Video Recipe:</p>
<p><iframe src="//www.youtube.com/embed/zf0_AJfp5AA" height="500" width="835" allowfullscreen="" frameborder="0"></iframe></p>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-05-18 21:38:50

您的查询已关闭,但您需要使用LOCATE和INSTR查找嵌入字符串的结尾:

代码语言:javascript
运行
复制
select 
  ID, 
  post_title, 
  substr(post_content,
   instr(post_content,'<div style="position:absolute'), 
   LOCATE('</div>',post_content,instr(post_content,'<div style="position:absolute')+30)-instr(post_content,'<div style="position:absolute')
   +6) as temp 
from wp_posts 
where post_content LIKE '%<div style="position:absolute%' 
LIMIT 10

参见这里的示例:http://sqlfiddle.com/#!2/d0cf2f/13

票数 1
EN

Stack Overflow用户

发布于 2015-04-11 23:16:33

答案是以下各点的变化:

代码语言:javascript
运行
复制
update wp_posts
set post_content = CONCAT(LEFT(post_content, LOCATE('div style=', post_content)-1),  
                   SUBSTRING(post_content, LOCATE('</div>', post_content)+7))
where LOCATE('div style=', post_content) > 0

将"div样式“更改为任何起作用的开始。

票数 2
EN

Stack Overflow用户

发布于 2021-05-26 15:13:58

对于此替换,可以使用以下查询:

代码语言:javascript
运行
复制
UPDATE Customer SET address = REPLACE(address, substring_index(substring_index(address, 'prefixString', -1), 'postfixString', 1), '') WHERE address IS NOT NULL;

例如:

地址:黑鹿街

用空字符串替换助推器

代码语言:javascript
运行
复制
UPDATE Customer SET address = REPLACE(address, substring_index(substring_index(address, 'Black', -1), 'deer', 1), ' ') WHERE address IS NOT NULL;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23726256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档