How to extract a string from a larger string?

前端 未结 3 1864
野的像风
野的像风 2021-01-20 17:39

Using jQuery how would I find/extract the \"Spartan\" string if the outputted HTML page had the following..



        
3条回答
  •  自闭症患者
    2021-01-20 18:07

    As well as using regular expressions, I've also abusively used these functions to do the things it seems you want to do (strip html and such from a text string):

    //removes all HTML tags
    function striptags(stringToStrip) {
        return stringToStrip.replace(/(<([^>]+)>)/ig,"");
    }
    //standard trim function for JavaScript--removes leading and trailing white space
    function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g,"");
    }
    

    Incredible regular expressions that have saved me a lot of time.

提交回复
热议问题