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>

8
  • 5
    I think I can say, with some certainty, yes. Commented Jan 26, 2015 at 4:18
  • 3
    What have you tried? Commented Jan 26, 2015 at 4: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. Commented Jan 26, 2015 at 4: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. Commented Jan 26, 2015 at 4:27
  • 1
    You could use a regex to remove anything that is not a whitespace or an alphanumeric character.... Commented Jan 26, 2015 at 4:40

1 Answer 1

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(' '));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.