1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

BB Code Option Validation

Discussion in 'XenForo Development Discussions' started by we_are_borg, Mar 1, 2016.

  1. we_are_borg

    we_are_borg Active Member

    Can you give an example based on this code

    <span style="background-color: {option}; padding: 0 2px">{text}</span>
    Usage: [bg=red]This is some text with a red background[/bg]
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Something like this, which is what I use for my custom background colour bb code:
    Matthew S, we_are_borg and Chris D like this.
  3. Chris D

    Chris D XenForo Developer Staff Member

    This is the "Option Match Regular Expression" from the GALLERY BB code from XFMG:
    ^^^ Brogan's example is also good :)

    In terms of escaping the option, you may have already seen that in the other code example I gave:
    $type $formatter->filterString(array_shift($parts),
    array_merge($rendererStates, array(
    'stopSmilies' => true,
    'stopLineBreakConversion' => true
    For any further support with this, it would be most appropriate to create a new thread in the XenForo Development Discussions forum.
    Matthew S and we_are_borg like this.
  4. we_are_borg

    we_are_borg Active Member

  5. we_are_borg

    we_are_borg Active Member

    Thank you moderator for splitting this topic from the bug report.

    The code that brogan gave worked like a charm no lets see if i can read it correctly am i novice on regular expressions.

    What i read here if someone uses rgb to define the color that he is only allowed to use numbers and two coma's. But how do you limit the to max 3 numbers in the sequence, that not clear to me?

    The | i assume is the next part of the regular expression

    If some one put the color up in hex then its limited to numbers and a, b, c, d, e and f. The question here is how the expression knows that 1234567 is not a valid sequence and what is the {3} for

    The next one is for named colors you say only letters may be used. But what is the $/i for?

    Thank you for learning me new stuff i did not know you needed to use it to make BB Code save.
  6. Chris D

    Chris D XenForo Developer Staff Member

    FWIW I think you may have copied the regex from the screenshot incorrectly.
    In the rgb case it ensures that 3 numerical values can be entered, separated by commas.

    It matches a string that is exactly 3 characters long, and the characters must be one of 0-9 or a-f. 1234567 is not valid because it is more than 3 characters.

    There's another bit you missed before that which is similar, but it matches a string which is 6 characters long.

    The start of the regex has a ^, this asserts the match must begin at the start of the string. $ is the opposite. It asserts the match must now be at the end of the string.

    Typical example:

    "#ff0000" will match but
    "#ff0000 blah" will not match

    The / is the delimiter - there's one at the beginning, too. It's the start and end of the pattern. The i is a modifer. There are others, but i basically allows the match to be case insensitive. In short, this would match, too, despite the pattern seemingly only allowing a-f (lower case):

    ozzy47, we_are_borg and Brogan like this.
  7. we_are_borg

    we_are_borg Active Member

    Like your explanation its clear and easy to understand.

Share This Page