1

Is there anyway to remove the characters before fa-?

[]

fa-deviantart
[]

fa-diamond
[]

fa-digg
[]

fa-dollar
(alias)
[]

fa-dot-circle-o
[]

fa-download
[]

fa-dribbble
[]

$(document).ready(function() {
  // var myfa = "fa-";
  // var findFA = myfa.substr(myfa.length - 3); // => "fa-"
  
  $("textarea").val( $("div").html().replace(/fa-/g,".fa .fa-") );
  $("div").html( $("textarea").val() );
});
div {
  white-space: pre-line;
  position: absolute;
  top: 200px;
  top: 100px;
}

textarea {
  position: absolute;
  width: 90%;
  left: 5%;
  padding: 0;
  height: 100px;
}
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <link type="text/css" rel="stylesheet" href="http://necolas.github.io/normalize.css/3.0.1/normalize.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
  </head>
  <body>
    <textarea></textarea>
    <div>
      
      fa-bitcoin
      (alias)
      []
      
      fa-bold
      []
      
      fa-bolt
      []
      
      fa-bomb
      []
      
      fa-book
      []
      
      fa-bookmark
      []
      
      fa-bookmark-o
      []
      
      fa-briefcase
      []
      
      fa-btc
      []
      
      fa-bug
      []
      
      fa-building
      []
      
      fa-building-o
      []
      
      fa-bullhorn
      []
      
      fa-bullseye
      []
      
      fa-bus
      []
      
      fa-buysellads
      []
      
      fa-cab
      (alias)
      []
      
      fa-calculator
      []
      
      fa-calendar
      []
      
      fa-calendar-o
      []
      
      fa-camera
      []
      
      fa-camera-retro
      []
      
      fa-car
      []
      
      fa-caret-down
      []
      
      fa-caret-left
      []
      
      fa-caret-right
      []
      
      fa-caret-square-o-down
      []
      
      fa-caret-square-o-left
      []
      
      fa-caret-square-o-right
      []
      
      fa-caret-square-o-up
      []
      
      fa-caret-up
      []
      
      fa-cart-arrow-down
      []
      
      fa-cart-plus
      []
      
      fa-cc
      []
      
      fa-cc-amex
      []
      
      fa-cc-discover
      []
      
      fa-cc-mastercard
      []
      
      fa-cc-paypal
      []
      
      fa-cc-stripe
      []
      
      fa-cc-visa
      []
      
      fa-certificate
      []
      
      fa-chain
      (alias)
      []
      
      fa-chain-broken
      []
      
      fa-check
      []
      
      fa-check-circle
      []
      
      fa-check-circle-o
      []
      
      fa-check-square
      []
      
      fa-check-square-o
      []
      
      fa-chevron-circle-down
      []
      
      fa-chevron-circle-left
      []
      
      fa-chevron-circle-right
      []
      
      fa-chevron-circle-up
      []
      
      fa-chevron-down
      []
      
      fa-chevron-left
      []
      
      fa-chevron-right
      []
      
      fa-chevron-up
      []
      
      fa-child
      []
      
      fa-circle
      []
      
      fa-circle-o
      []
      
      fa-circle-o-notch
      []
      
      fa-circle-thin
      []
      
      fa-clipboard
      []
      
      fa-clock-o
      []
      
      fa-close
      (alias)
      []
      
      fa-cloud
      []
      
      fa-cloud-download
      []
      
      fa-cloud-upload
      []
      
      fa-cny
      (alias)
      []
      
      fa-code
      []
      
      fa-code-fork
      []
      
      fa-codepen
      []
      
      fa-coffee
      []
      
      fa-cog
      []
      
      fa-cogs
      []
      
      fa-columns
      []
      
      fa-comment
      []
      
      fa-comment-o
      []
      
      fa-comments
      []
      
      fa-comments-o
      []
      
      fa-compass
      []
      
      fa-compress
      []
      
      fa-connectdevelop
      []
      
      fa-copy
      (alias)
      []
      
      fa-copyright
      []
      
      fa-credit-card
      []
      
      fa-crop
      []
      
      fa-crosshairs
      []
      
      fa-css3
      []
      
      fa-cube
      []
    </div>
  </body>
</html>
Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
Michael Schwartz
  • 8,153
  • 14
  • 81
  • 144
  • 5
    I think I can say, with some certainty, *yes*. – Alexander O'Mara Jan 26 '15 at 04:18
  • 3
    [What have you tried?](http://mattgemmell.com/what-have-you-tried/) – elixenide Jan 26 '15 at 04:21
  • I've been playing with .substr() and .slice() but I'm confused on how to grab the weird symbols before `fa-` like ``. I tried using replace() in order to grab the .substr() before but can't get it to work. – Michael Schwartz Jan 26 '15 at 04:24
  • Can you add the output you are trying to achieve? Adding the code you have tried but couldn't get to work would also be nice. – Alexander O'Mara Jan 26 '15 at 04:27
  • I'd also really like to know what exactly are you doing that causes those strange symbols. – Jhecht Jan 26 '15 at 04:28
  • The strange symbols is from a copy and paste from fontAwesome & some editing to make it easier so I get the class names instead of the weird characters - https://fortawesome.github.io/Font-Awesome/cheatsheet/ – Michael Schwartz Jan 26 '15 at 04:35
  • 1
    You could use a regex to remove anything that is not a [whitespace](http://stackoverflow.com/questions/5963182/how-to-remove-spaces-from-a-string-using-javascript) or an [alphanumeric](http://stackoverflow.com/questions/9364400/remove-not-alphanumeric-characters-from-string-having-trouble-with-the-char) character.... – nem035 Jan 26 '15 at 04:40
  • Did you want to remove the square brackets as well? What output/end-result do you want? – David Thomas Jan 26 '15 at 05:11

1 Answers1

2

You could use a regex to match valid class names starting with fa-.

//A string you want to extract the classes from.
var exampleString = 'fa-deviantart[]fa-diamond[]';

//Extract the class names using a regex into an array.
var classList = exampleString.match(/fa\-[a-zA-Z0-9\-_]*/g);

//Create a new string from the array of matched classes.
alert(classList.join(' '));
Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171