Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement the regular expression of all spaces before and after the string is removed

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to implement the regular expression of all spaces before and after removing the string. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Regular expression, also known as regular representation, conventional representation (English: Regular Expression, often abbreviated to regex, regexp or RE in code), is a concept in computer science. Regular expressions use a single string to describe and match a series of strings that conform to a syntactic rule. In many text editors, regular expressions are often used to retrieve and replace text that matches a certain pattern.

/ * * remove all spaces before and after the string * / function trim (str) {return str.replace (/ (^\ s*) | (\ sblank $) / g, "");} / / calculate 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;} //验证活动标题function vailTitle(){//var title = $("#title").val();var title =trim($("#title").val());var flag = false;var message = "";var length = getNickNameLength();if(title == ''){message = "标题不能为空!";}else if(length>

20) {message = "title within 20 characters!" ;} else {flag = true;} if (! flag) {$("# lr1") .html (message);} else {$("# lr1"). Html ("");} return flag;} / / check $("# title") .blur (function () {vailTitle ();}) when the cursor leaves; / / hide / * $("# title"). On ('keyup',function (e) {$("# lr1"). Html ("). Hide () ); * / $("# title") .focus (function () {$("# lr1") .html ("");})

Regular expression _ removes any space in a string (Regex)

Directly with-split, separated by white space by default.

-split $a

Regular expressions can be used directly in regular expressions, and so can select-string in select-string.

Split and join use spaces by default, while replace uses spaces by default

$a-split'\ s roommates a-replace ("\ s +", "`n")

Using split method

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

Replace the space with the replacement method

[regex]:: replace ($a, "\ b\ s +\ b", ") .split (")

Fetch the required value with a non-empty expression

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

Select-string:

This is the end of this article on "how to implement the regular expression of all spaces before and after the string is removed". I hope the above content can be helpful to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report