开发者

MySQL: Formatting a string

My database contains a string pattern that is 开发者_JS百科used to allow for easy user editing via a JS-script.

The string is basicly formatted like so:

aaa[bbb#ccc]ddd[eee#fff]ggg

the result I am looking for is

aaacccdddfffggg

I'd like to do this when selecting the string from the database. I'm guessing a regex should do the trick. But my knowledge in the subject of regex's is rather limited. However, this is not a requirement, if there exist a more elegant solution to the problem.


Unfortunately, you can only use a MySQL REGEXP in a WHERE clause, to match against values. You can't use them to transform Strings.

You'll either need to do it clientside, or work with the other String Functions. A MID() would do the trick, if the lengths and positions of the substrings are fixed. If not, use POSITION() (or LOCATE()) to find the special characters []#.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜