Tuesday 16 January 2018

mysql - How to delete strings which contain random characters by regex syntax

itemprop="text">

I have a text file (.sql database)
which containings these
strings



[center:t1jrwz84]
[center:18gl5k7g]

[center:3tkgm3zz]
[center:1jrwz84d]


They
appear in text file like
this



Hello [center:t1jrwz84]
everyone. How are[center:18gl5k7g]you today?
Glad to meet[center:3tkgm3zz]
you. Thanks for[center:1jrwz84d]
coming.



How
to delete all strings by replace function of Editor Notepad++, Sublime, ... with regex
syntax?



I try this regex syntax in
Notepad++



- Find what:
[[center].*.[]]
- Replace
with:


And this is the
result




Hyou
today?
Glad
coming.


Of course this
is wrong. It isn't my target. My target
is



Hello everyone. How are you
today?
Glad to meet you. Thanks for
coming.



PS:
I want to delete theme because these are wrong bbcodes, html tags in the posts of smf
forum database. I converted it from phpbb (center, right, justify, font, ...) with
custom bbcode and Almsamim WYSIWYG Editor. MySQL doesn't support regex syntax in replace
query, UDF addon is so complicated, so i have to do it with .sql file and Text
Editor.



Answer




You need a href="http://www.regular-expressions.info/optional.html"
rel="nofollow">non-greedy capture; the .* needs to
be qualified with a ? to keep from swallowing everything up to
the last ']' on the line.



Find:
\[center\:(.*?)\]



and
replace with nothing. Here I've also removed extraneous brackets and escaped the '[',
']', and ':' with backslashes.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...