当前位置:网站首页>正则表达式小实例--去掉字符串中间和两边的空格
正则表达式小实例--去掉字符串中间和两边的空格
2022-08-05 05:19:00 【CrazyQiQi】
通过正则表达式将字符串中的所有空格去除
var str = " gs gdjkf gs gfsd ";
str = str.trim(); //trim()只能去除字符串两边的空格
var getNewStr = function(str) {
//通过正则表达式,去除字符串中的空白符
var reg = /^\s+|\s+|\s+$/g; //匹配开头结尾和中间的所有空白符
str = str.replace(reg, ''); //用''将匹配到的空白符全部替换掉
return str;
}
getNewStr(str); //此时获取的到的就是没有空格的字符串
//gsgdjkfgsgfsd
边栏推荐
- Dsf5.0 bounced points determine not return a value
- Servlet跳转到JSP页面,转发和重定向
- Spark源码-任务提交流程之-6.1-sparkContext初始化-创建spark driver端执行环境SparkEnv
- 【3D模型教程】ZBrush如何表现皮肤纹理?
- 【Machine Learning】1 Univariate Linear Regression
- spark源码-任务提交流程之-1-sparkSubmit
- lvm logical volume and disk quota
- spark算子-wholeTextFiles算子
- Getting Started 11 Automatically add version numbers
- Apache configure reverse proxy
猜你喜欢

【Day8】Knowledge about disk and disk partition

入门文档08 条件插件

I/O性能与可靠性

TCP/IP four-layer model

Account and Permission Management
![[Day5] Soft and hard links File storage, deletion, directory management commands](/img/15/7ed58a180a72ace3463626bf446633.png)
[Day5] Soft and hard links File storage, deletion, directory management commands

Configuration of TensorFlow ObjecDetectionAPI under Anaconda3 of win10 system

【3D模型教程】ZBrush如何表现皮肤纹理?

Getting Started 04 When a task depends on another task, it needs to be executed in sequence

偷题——腾讯游戏开发面试问题及解答
随机推荐
Apache configure reverse proxy
ROS视频教程
OpenCV3.0 is compatible with VS2010 and VS2013
Remembering my first CCF-A conference paper | After six rejections, my paper is finally accepted, yay!
你要找的cocos面试答案都在这里了!
IP数据包格式(ICMP协议与ARP协议)
专有宿主机CDH
Getting Started Document 07 Staged Output
[Day5] Soft and hard links File storage, deletion, directory management commands
UE4动画雨滴材质制作教程
网站ICP备案是什么呢?
Getting Started Documentation 12 webserve + Hot Updates
UE4美术你有必要了解的数学基础
【Day8】(超详细步骤)使用LVM扩容
[Pytorch study notes] 8. How to use WeightedRandomSampler (weight sampler) when the training category is unbalanced data
Spark源码-任务提交流程之-6.2-sparkContext初始化-TaskScheduler任务调度器
spark源码-任务提交流程之-1-sparkSubmit
Getting Started 04 When a task depends on another task, it needs to be executed in sequence
海外服务器的优势
添加新硬盘为什么扫描不上?如何解决?