The regular expression _ regular expression that removes all spaces before and after the string

Source: Internet
Author: User

Regular expressions, also known as formal representations, general representations (English: Regular Expression, often abbreviated as regex, RegExp, or re) in code, a concept of computer science. A regular expression uses a single string to describe and match a series of strings that conform to a certain syntactic rule. In many text editors, regular expressions are often used to retrieve and replace text that conforms to a pattern.

/** remove all spaces before and after the string *
/function trim (str) {return 
str.replace (^\s*) | ( \s*$)/g, ""); 
Calculates the title length
function getnicknamelength () {
var title = $ ("#title"). Val ();
var len = 0;
for (var i = 0; i < title.length i++) {
var a = Title.charat (i);
if (A.match (/[^\x00-\xff]/ig)!= null) {
len + + 2;
} else{
len + + 1;
}
}
return len;
} 
Verify Activity title
function Vailtitle () {
//var title = $ ("#title"). Val ();
var title =trim ($ ("#title"). Val ());
var flag = false;
var message = "";
var length = Getnicknamelength ();
if (title = = ') {message
= ' title cannot be empty! ";
} else if (length>20) {message
= "title is 20 characters characters! ";
} else{
flag = true;
}
if (!flag) {
$ ("#lr1"). HTML (message);
else{
$ ("#lr1"). HTML ("");
return flag;
}
Check
$ ("#title") when the cursor leaves. blur (function () {
vailtitle ();
});
Hide/
* $ ("#title") when the focus is obtained. On (' KeyUp ', function (e) {
$ ("#lr1"). HTML (""). Hide ();
*
/$ ("#title"). focus (function () {
$ ("#lr1"). HTML ("");
});

Regular expression _ Delete any space in the string (Regex)

Directly with-split, the default is whitespace delimited.

-split $a

Regular expressions can be used directly in \s,-replace-split in regular expressions, and select-string can also

Split and join default use space, replace default use empty

$a-split ' \s+ '
$a-replace ("\s+", "' N")

Using the Split method

[Regex]::split ($a, "\b\s+\b")

Replace space with substitution method

[Regex]::replace ($a, "\b\s+\b", ""). Split ("")

To remove a value that meets a requirement with a non-empty expression

[Regex]::matches ($a, "\b\s+\b") | %{$_.value}


Select-string:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.