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.
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: