正则表达式删除空间 [英] REGEX Remove Space

查看:65
本文介绍了正则表达式删除空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建正则表达式来删除一些匹配的字符串,字符串是电话号码

I want to creating regex to remove some matching string, the string is phone number

示例用户输入电话号码如下:

Example user input phone number like this:

+jfalkjfkl saj f62 81 7876 asdadad30 asasda36

然后输出将是这样的:

628178763036

目前使用我当前的正则表达式 ^[\+\sa-zA-Z]+ 它可以选择部分 +jfalkjfkl saj f

at the moment with my current regex ^[\+\sa-zA-Z]+ it can select the part +jfalkjfkl saj f

什么是正则表达式所以它也可以选择数字之间的空格?

What is the regex so it also can select the space bewteen number?

例如:

62(此处选择空格)81, 81(此处选择空格)7876

推荐答案

我不知道你打算在什么语言中使用它,但你可以替换这个模式:[^\d]+,使用空字符串应该可以完成此操作.它将删除所有不是数字的内容.

I don't know what language you plan on using this in, but you can replace this pattern: [^\d]+, with an empty string should accomplish this. It'll remove everything that's not a number.

这篇关于正则表达式删除空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆