LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-27-2023, 08:03 PM   #1
Aeolustw
Member
 
Registered: Jun 2009
Location: Taiwan
Distribution: Linux Debian (or CentOS)
Posts: 57

Rep: Reputation: 2
Question UPDATE REPLACE random string with same beginning and ending in MariaDB 10


Hi,
The strings:
<r>[quote name='Angel' date='Jan 5 2005, 21:36 PM']...
<r>[quote name='ABC' date='Mar 7 2005, 13:07 PM']...
<t>[quote name='DEF' date='Sep 2 2005, 22:10 PM']...

I want to replace [quote name='DEF' date='Sep 2 2005, 22:10 PM'] with <QUOTE><s>[quote]</s>
The beginning string is [quote name= and the end one is ']
And I try:
Code:
UPDATE phpbb_posts SET post_text = REGEXP_REPLACE (post_text, '\[quote name=.*\'\]' , '<QUOTE><s>[quote]<\/s>') WHERE post_text LIKE '%quote name=%' ;
The results data in show too many:
<r>[<QUOTE><s>[quote]</s><QUOTE><s>[quote]</s><QUOTE><s>[quote]</s>...

Ant hit?
Thanks.

Last edited by Aeolustw; 11-08-2023 at 05:46 PM.
 
Old 10-28-2023, 12:35 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,868
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
If you want to change lines with 'DEF', then it should be part of the WHERE-clause, e.g.
Code:
UPDATE phpbb_posts
SET post_text = REGEXP_REPLACE (post_text, from, to)
WHERE post_text LIKE '%quote name=%DEF%';
 
1 members found this post helpful.
Old 10-28-2023, 04:41 AM   #3
Aeolustw
Member
 
Registered: Jun 2009
Location: Taiwan
Distribution: Linux Debian (or CentOS)
Posts: 57

Original Poster
Rep: Reputation: 2
NevemTeve,
Thanks,
I have 168 posts,
it fixed now.(no poster and post time)
Code:
UPDATE phpbb_posts SET post_text = REGEXP_REPLACE (post_text, "\[quote name=.*\']" , '<QUOTE><s>[quote]<\/s>') WHERE post_text LIKE '%quote name=%' ;

Last edited by Aeolustw; 10-31-2023 at 06:22 PM.
 
Old 10-28-2023, 04:46 AM   #4
Aeolustw
Member
 
Registered: Jun 2009
Location: Taiwan
Distribution: Linux Debian (or CentOS)
Posts: 57

Original Poster
Rep: Reputation: 2
If i want to keep poster and post time
change
<r>[quote name='Angel' date='Jan 5 2005, 21:36 PM']...
to
<r>[<QUOTE><s>[quote]</s>Angel' date='Jan 5 2005, 21:36 PM']...
Use these codes:
Code:
UPDATE phpbb_posts SET post_text = REPLACE (post_text, '[quote name=' , '<QUOTE><s>[quote]<\/s>') WHERE post_text LIKE '%quote name=%';

Last edited by Aeolustw; 10-28-2023 at 09:07 AM. Reason: use simple codes
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] replace all characters from the beginning of the string to right most slash in sed li Sushama Slackware 5 04-29-2015 04:59 AM
[SOLVED] remove certain lines from file based on start of line except beginning and ending nwalsh88 Linux - Newbie 5 02-20-2013 10:20 AM
how do i replace a text string in a file with a random string? (with sed etc) steve51184 Linux - Software 16 09-02-2010 11:05 AM
need sh script advice to replace random string luw Linux - General 8 09-01-2010 03:11 PM
LXer: From the End of the Beginning to the Beginning of the End LXer Syndicated Linux News 0 03-08-2009 12:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration