0

I have a row with content that can look like this:

bla bla bla [ATTACH]123456[/ATTACH] bla bla bla
bla bla bla [ATTACH]78912[/ATTACH] bla something bla

I need to search the row for all occurences of [ATTACH]number[/ATTACH] and replace it like this:

[ATTACH]123456[/ATTACH] should become [sharedmedia=core:attachments:123456]

or...

[ATTACH]78912[/ATTACH] should become [sharedmedia=core:attachments:78912]

2
  • Great. Looks like fun. Commented Mar 15, 2014 at 16:02
  • Thank you for providing a report on the status of your current efforts. Did you have a question? Commented Mar 15, 2014 at 16:13

1 Answer 1

1

SQL is not optimized for this sort of work. The following might accomplish what you want:

update table t
    set content = replace(replace(content, '[ATTACH]', '[sharedmedia=core:attachments:'
                                 ), '[/ATTACH]', ']'
                         )
    where content like '[ATTACH]%[/ATTACH]';

This assumes that all occurrence of [ATTACH] are followed by a number.

Sign up to request clarification or add additional context in comments.

2 Comments

@Akyhne . . . That is why I always try to line up my parentheses, so I can visually see when I might be missing one.
Works this way: update table t set content = replace(replace(content, '[ATTACH]', '[sharedmedia=core:attachments:' ), '[/ATTACH]', ']' ) where content like '%[ATTACH]%[/ATTACH]%'; This assumes that all occurrence of [ATTACH] are followed by a number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.