Trim String (With Tabs & Returns)

myString = myString = ”               The quick brown fox.                           “;
pattern = /^\s+|\s+$/gs;
resultString = myString.replace(pattern, “”);
trace(resultString); // “The quick brown fox.”

Advertisements

One thought on “Trim String (With Tabs & Returns)

  1. karthikeyan.cs says:

    I am using the following code to validate the url given by the user.

    var pUrlString:String = “www.google.com”;
    var URL_REG_EXP:RegExp = /(ht|f)tp(s?):\/\/|www./;
    var isValidUrl:Boolean = false;

    if(pUrlString.match(ElementUtils.URL_REG_EXP) != null)
    {
    isValidUrl = true;
    if(!(URLUtil.isHttpsURL(pUrlString) || URLUtil.isHttpURL(pUrlString)))
    {
    pUrlString = “http://” + pUrlString;
    }
    }
    else
    {
    isValidUrl = false;
    }

    But in some cases the url given by the users are not starts with http or www, it not seems like the url, but contains the image in that path.

    ex : one of the sample url :

    data:image/jpg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBg8PDw8PEA8QEA8PDw8NDQ8PDQ4PDxAPFBAVFBQQEhQXGyYeFxklGRISHy8gIycpLCwsFR4xNTAqNSYrLCkBCQoKDgwOGg8PGiwfHx4sKS0pKSwpKSksLCksLCkpLCwpLCwpKSwsLCwpLCkpKSwpLCkpLCksLCwpKSksLCwsLP/AABEIANQA7gMBIgACEQEDEQH/xAAcAAACAgMBAQAAAAAAAAAAAAAAAQIHBAUGAwj/xABFEAACAQMABQULCgQGAwAAAAAAAQIDBBEFBhIhMQdBUWFxEyIyUlSBkZKTodEUFRYjQlNyg7HwM0Ni4SU0RKLB8TWCwv/EABsBAQACAwEBAAAAAAAAAAAAAAABBQIEBgMH/8QALxEAAgICAAQEBQMFAQAAAAAAAAECAwQRBRIxURMhQXEyUmGBkRQiQjNDYqHRNP/aAAwDAQACEQMRAD8Au0Q2IATEiTIgEgEojAGAgAGLPWMTiAMQwAEAxAAAAAA0IACTEAiUAAAJAxDEYoAAASwMQAQAGAgBiPC5uoU1mc4wXTKSS95j/PVt9/S9rD4gzUG1tIzwMH57tvKKPtYfEcd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J+49KsnxHrRX53DIY1XOpbO3kV/yq6ZcKdK3g2pTfdJNPDUVw95YEluKN16vp1r6q5JpQfc4JprvY86857Xy5YbR4cKpVt6b6I2GgOUm4t8Qqru8FwbffxXU+ctTQulY3VCFeCkozW5TWGUToPRcrq4p0I576S2njhDi3+pftjaxpU4U4rEYxUYrsR5Y05yW2bPGaqapLkWm+pkpAMRtFDsYgAEAMQACaGhiyALIsgGCQBIjgkQAMC+0Jb3DUq1KFRpYi5LOEZ4wzJScXtM0n0RsfJaXqInDVWyjwtaXqJm3Aw5I9j18ez5n+TVrVyzX+mo+yiT+Ybbyel7OJsQHIuxHjWd3+TAWhrf7ikvy4/AfzNb/AHNL1I/AzsAkTyrsR4k+7/Jg/M1v9xS9SPwF8y2/3FL2cTYYDBPKuw8WfzP8mv8AmS2+4peziJ6EtvJ6Xs0bHZFskcq7DxZ/M/ya2WgLV8bel7OJlWllTpR2acIwjnOIxSXoMgCVFIhznJak2wwazS2rttdRca1OMuvhJdjNmBLSfUxjKUHuL0zmdXdR6NjVqVISlJzSjFS37CXQzpYr+xLAGMYqPkjKy2dr3N7EAAZHmAAAAAAwBMjgmxACSGAEAAACQMBDAAAyAAAAgTsYZEAIHkAEAMBDBOwAMgAACAAYgAEAAAAAAAADEMABEyIAgAAAAAAAAAABiAABiAABiz7xsAABEgCADwAAAGAwCBAMMAkAAMAAIeAwAAAAAhiHkAESAACIgAAYMQAAMQADYgAAAAACSGAACBAAA2JCAAkAAAAAAAAAAAAAAJhIAAIjQgAP/9k=

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s