#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18

    Javascript regular expressions - changing HTML to vBcode


    I'm working on a mod for vBulletin, and I was hoping somebody can help me change 3 specific font tag values to their vBcode counterparts:

    <font size="n">x</font> needs to become [size= n]x[/ size],
    <font color="n">x</font> needs to become [color= n]x[/ color],
    and <font face="n">x</font> needs to become [font= n]x[/ font].

    I've been rackin my brain the past 12 hours, tried several dozen different approaches, and have had no luck whatsoever. If somebody can give me a hand with this I'd greatly appreciate it.
    To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    It doesn't handle nested tags or multiple font attributes, but it's a start

    Code:
    var text = "<font size='3' face='arial'>testing</font>";
    
    var vbText = text.replace( /<font.*size=['"]([^'"]+)["'].*>([^<]*)<\/font>/, "[**REMOVE THIS**size=$1]$2[/size]" );
    -james
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18
    Thanks, I'll tinker around with this and see what I can do.
    To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson

IMN logo majestic logo threadwatch logo seochat tools logo