# Migrate a vBulletin 4 forum to Discourse

**URL:** <https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881>\
**Category:** Sysadmins\
**Tags:** how-to\
**Created:** [28 december 2016 om 14:59 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881 "2016-12-28T14:59:29Z")\
**Posts on this page:** 1\
**Showing post:** 177

<div class="post-metadata">

**Author:** ![taravasya](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/taravasya/32/214539_2.png) [@taravasya](https://meta.discourse.org/u/taravasya)\
**Post date:** [27 juli 2024 om 22:56 UTC](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881/177 "2024-07-27T22:56:17Z")

</div>

Hi. Just want to share my solution.  
As for the problems with quotes. As I said before, i’m was facing with problems - regexp not capture quotes then:

- username and post id may be enclosed in double quotes
- nested quotes

I decided to do a search and replace using a different logic. Instead of searching for tags and their contents, I used a regular expression that searches **only for tags** :

was:  
` raw.gsub!(%r{\[quote="?([^;]+);(\d+)"?\](.+?)\[\/quote\]}im) do`

 ![image](https://global.discourse-cdn.com/meta/original/4X/3/4/7/347dbb3650251efb12bdc9680b24b96ec91b9264.png)

became:  
` raw.gsub!(%r{(\[QUOTE(="?([^;]+);(\d+)"?)?\])|(\[\/QUOTE\])}im) do`

 ![image](https://global.discourse-cdn.com/meta/original/4X/1/4/0/140429e87f9779262c555cda18c9092336f9bf6b.png)

and then little change the determining the source of a quote:

```plaintext
      if $3 && $4
        if topic_lookup = topic_lookup_from_imported_post_id(post_id)
          post_number = topic_lookup[:post_number]
          topic_id = topic_lookup[:topic_id]
          "\n[quote=\"#{new_username},post:#{post_number},topic:#{topic_id}\"]\n"
        else
          "\n[quote=\"#{new_username}\"]\n"
        end
      elsif $5
        "\n[/quote]\n"        
      end

```

Also, I change the spoiler’s code. Instead of:

```plaintext
    # [spoiler=Some hidden stuff]SPOILER HERE!![/spoiler]
    raw.gsub!(%r{\[spoiler="?(.+?)"?\](.+?)\[/spoiler\]}im) do
      "\n#{$1}\n[spoiler]#{$2}[/spoiler]\n"
    end

```

that blured text, I convert it to details tag:

```plaintext
    raw.gsub!(%r{(\[spoiler(="?(.*?)"?)?\])|(\[\/spoiler\])}im) do
      if $3
        "\n[details=#{$3}]\n"
      elsif $1
        "\n[details]\n"
      elsif $4
        "\n[/details]\n"
      end
    end

```

Because it just so happens that in the vbulletin world - sploiler it is not the blurred content, but rather the collapsed content. So I think it is much more appropriate for the vbulletin import script to convert spoilers to details instead of the blurred spoiler.

I also noticed the mention tag. In my case, in vbulletin, the mentions looked like this:  
[mention=XXX]username[/mention]

The regular expression used in the script does not take into account that the tag may contain the user id.

```plaintext
    # [MENTION]<username>[/MENTION]
    raw.gsub!(%r{\[mention\](.+?)\[/mention\]}i) do
      new_username = get_username_for_old_username($1)
      "@#{new_username}"
    end

```

I fixed this in my own way too:

```plaintext
    # [MENTION]<username>[/MENTION]
    raw.gsub!(%r{\[mention(=\d+)?\](.+?)\[/mention\]}i) do
      new_username = get_username_for_old_username($2)
      "@#{new_username}"
    end

```

---

_[View the full topic](https://meta.discourse.org/t/migrate-a-vbulletin-4-forum-to-discourse/54881)._
