JQuery Remove Text Before String

Michael Schwartz

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

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(' '));

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Remove All Character before a String and the String itself

분류에서Dev

Jquery remove dynamic element before current element

분류에서Dev

Using find() in Excel to remove text from string

분류에서Dev

How can I extract text before a character or string in a batch file?

분류에서Dev

I want to remove static text from string - iOS

분류에서Dev

how to remove a multilined string/block of text pattern from a file?

분류에서Dev

C# Full-text search string format : string remove all adjacent duplicates and append with 'AND' 'OR'

분류에서Dev

Setting textbox text to a old date but not allowing the user to select dates before today for jquery datepicker

분류에서Dev

Remove code before <html> tag

분류에서Dev

Asterisk before the string in a regex

분류에서Dev

Asterisk before the string in a regex

분류에서Dev

HTML Redirecting with text before the domain

분류에서Dev

JQuery remove styles added

분류에서Dev

jQuery remove () 함수

분류에서Dev

Remove elements on click with jQuery

분류에서Dev

How to remove private code before publishing?

분류에서Dev

Bash - Remove the last character of the line this before?

분류에서Dev

Remove everything before br tag Regex

분류에서Dev

How to remove , in the string in javascript

분류에서Dev

grep for string without another string before it

분류에서Dev

Remove special characters in a text file

분류에서Dev

How to replace </body> and Insert a text before it?

분류에서Dev

return all the text before the first comma

분류에서Dev

bash Add text before and after match

분류에서Dev

formatting a text file before mailing it in shell script

분류에서Dev

Change result group text before replacing?

분류에서Dev

substr to find all text before a wildcard substring

분류에서Dev

Add text to end of the filename but before extension

분류에서Dev

Display README or WARNING text before package removal

Related 관련 기사

  1. 1

    Remove All Character before a String and the String itself

  2. 2

    Jquery remove dynamic element before current element

  3. 3

    Using find() in Excel to remove text from string

  4. 4

    How can I extract text before a character or string in a batch file?

  5. 5

    I want to remove static text from string - iOS

  6. 6

    how to remove a multilined string/block of text pattern from a file?

  7. 7

    C# Full-text search string format : string remove all adjacent duplicates and append with 'AND' 'OR'

  8. 8

    Setting textbox text to a old date but not allowing the user to select dates before today for jquery datepicker

  9. 9

    Remove code before <html> tag

  10. 10

    Asterisk before the string in a regex

  11. 11

    Asterisk before the string in a regex

  12. 12

    HTML Redirecting with text before the domain

  13. 13

    JQuery remove styles added

  14. 14

    jQuery remove () 함수

  15. 15

    Remove elements on click with jQuery

  16. 16

    How to remove private code before publishing?

  17. 17

    Bash - Remove the last character of the line this before?

  18. 18

    Remove everything before br tag Regex

  19. 19

    How to remove , in the string in javascript

  20. 20

    grep for string without another string before it

  21. 21

    Remove special characters in a text file

  22. 22

    How to replace </body> and Insert a text before it?

  23. 23

    return all the text before the first comma

  24. 24

    bash Add text before and after match

  25. 25

    formatting a text file before mailing it in shell script

  26. 26

    Change result group text before replacing?

  27. 27

    substr to find all text before a wildcard substring

  28. 28

    Add text to end of the filename but before extension

  29. 29

    Display README or WARNING text before package removal

뜨겁다태그

보관