Replace a string in all posts


#64

Try this:
rake posts:delete_word["[font='Open Sans'\, sans-serif]"]

There is an extra backslash in your example and the quotes are actually opening and closing single quotes instead of straight single quotes.


(Jay Pfaffman) #65

There is a bbcode plugin that might solve your problem.


#66

It works. But doesnt work with that:

rake posts:delete_word["[font=\‘Helvetica Neue\’\, Helvetica\, Arial\, sans-serif]"]

And it doesnt work too:

rake posts:delete_word["[font=‘Helvetica Neue’\, Helvetica\, Arial\, sans-serif]"]

@pfaffman I am already deleted [/font] tags. But thanks for idea.


#67

You should only escape the comma, not the single quote, and it seems your text editor is converting straight quotes to opening and closing quotes:


(Coin-coin le Canapin) #68

Hi,
What should be the exact syntax when using a regex ? I’m trying to do this:

rake posts:delete_word["/\[color.*?]|\[\/color\]|\[size.*?]|\[\/size\]/"]

in order to remove all the old bb tags, but it doesn’t work.

edit : nevermind, I got it:

rake posts:delete_word['\[color.*?]|\[\/color\]|\[size.*?]|\[\/size\]',regex]

Well it’s processing at least.


(Coin-coin le Canapin) #69

Is there any way to do a test as some were talking about? I’d like to see an excerpt of the result of my rake command if possible.
It’s still processing (lots of posts), but if there is any error or if I need to use rake another time in the future, that could be a good thing to test it without having to wait hours to see the outcome.

edit: yes, it was indeed a failure.
Maybe I forget to escape some ], but the regex is working here: RegExr: Learn, Build, & Test RegEx and here: Rubular: \[color.*?]|\[\/color\]|\[size.*?]|\[\/size\]

However, the rake command messed up my messages:
From:

Ma config de rêve ce serait:
Cadre : koxx type XTP en 29 pouces mais en CrMo [size=200][color=red]MgTi[/color][/size] (à créer)
Selle : fusion freeride avec base carbone [size=200][color=red]MgTi[/color][/size]
Tube de selle : pitfighter II en MgTi
Pneu : Nokian Gazzaloddi 29X3.25 (à créer)[size=200][color=red]MgTi[/color][/size]
Jante : Double paroi percée matrice en MgTi + fibre de Carbone (à créer) 
Axe : Schlumpf [size=200][color=red]MgTi[/color][/size]
Manivelles : Moment double insert 125/150 [size=200][color=red]MgTi[/color][/size]
Pédales : Try all MgTi
Serrage : 24 Cockring [size=200][color=red]MgTi[/color][/size]
Bon je cherche pas de prix [size=200][col`or=red]MgTi[/color][/size] mais à rêver...^^

to:

Ma nfg d êv at:
Cad : kxx typ XTP n 29 pu ma n CM [=200][=d]MgT[] (à é)
S : fun fd av ba abn [=200][=d]MgT[]
Tub d : ptfght II n MgT
Pnu : Nkan Gaadd 29X325 (à é)[=200][=d]MgT[]
Jant : Dub pa pé mat n MgT + fb d Cabn (à é)
Ax : Shumpf [=200][=d]MgT[]
Manv : Mmnt dub nt 125150 [=200][=d]MgT[]
Péda : Ty a MgT
Sag : 24 Ckng [=200][=d]MgT[]
Bn j hh pa d px [=200][=d]MgT[] ma à êv^^

It removed the individual letters (c, o, l, o, r, etc) on every message.
Maybe my escaping character \ is not right? What am I missing?

edit:
I tried an alternative regex suggested by a friend, but:

root@canapin-app:/var/www/discourse# rake posts:delete_word['\[color[^\]]*\]|\[\/color\]|\[size[^\]]*\]|\[\/size\]',regex]
Are you sure you want to remove all regex occurrences of '[color[^]]*]|[/color]|[size[^]]*]|[/size]'? (Y/n)
y
Processing
/var/www/discourse/lib/tasks/posts.rake:140: warning: character class has ']' without escape: /[color[^]]*]|[\/color]|[size[^]]*]|[\/size]/

Isn’t there an issue with escaping in the rake command?


(Cameron:D) #70

You may need multiple slashes, the first one probably only applies the escape to the bash command. I know with rsync commands in bash you need to use a triple backslash, so maybe try use two or three and see how that goes.

rake posts:delete_word['\\[color.*?\\]|...


(Coin-coin le Canapin) #71

Lol, if that doesn’t work I’d better try four! :sweat_smile:

Seems to work as it is processing, hope the result will be the right one. :slight_smile:

edit : it works, thanks!


(Coin-coin le Canapin) #72

I’m satisfied with the result, but there are still 19 remaining messages containing these tags (on 4000+ messages that were containing these tags before) that won’t be updated. I tried the command multiple times, see below.

root@canapin-app:/var/www/discourse# rake posts:delete_word['\\[color.*?\\]|\\[\\/color\\]|\\[size.*?\\]|\\[\\/size\\]',regex]
Are you sure you want to remove all regex occurrences of '\[color.*?\]|\[\/color\]|\[size.*?\]|\[\/size\]'? (Y/n)
y
Processing
...................
19 posts updated!

root@canapin-app:/var/www/discourse# rake posts:delete_word['\\[color.*?\\]|\\[\\/color\\]|\\[size.*?\\]|\\[\\/size\\]',regex]
Are you sure you want to remove all regex occurrences of '\[color.*?\]|\[\/color\]|\[size.*?\]|\[\/size\]'? (Y/n)
y
Processing
...................
19 posts updated!

How can you explain that?

Remaining messages:


(Kane York) #73

Hey, 19 false negatives is pretty good! You can just manually go fix those up. After all, you’re only doing this once, right?

Be happy with half a percent :slight_smile:


(Cameron:D) #74

Yeah, I tried the regex way and had the same problem so I called delete_word for each unique bbcode tag. It didn’t occur to me until just now, until “removed the individual letters (c, o, l, o, r, etc)” was mentioned, that double-escaping might be needed.


(Coin-coin le Canapin) #75

Yeah sure, that’s not that annoying, I just wonder why it refuses to update these ones.


(Mittineague) #76

My guess is it has something to do with the content beginning with a bbcode tag, and maybe greediness.

I hope you saved a backup. This post looks foobar

https://forum.cs-amx.org/t/ou-se-procurer-le-devil/739/8


(Ultra Noob) #77

Hi…
Is it normal?

I know particular word exist. Then why fail? :thinking:


Update: despite failure, It seems working globally wherever string exist.