需要帮助查找javascript代码吗
我面临着这个问题。我得到了这样的字符串需要帮助查找javascript代码吗,javascript,jquery,Javascript,Jquery,我面临着这个问题。我得到了这样的字符串 '=--satya','=---satya1','=-----satya2'. 现在我的问题是我必须删除这些特殊字符并像这样打印字符串 'satya' 'satya1' 'satya2' 请帮助解决此问题?使用javascript函数,该函数可帮助您在这种情况下使用正则表达式 var string = '=---satya1'; string = string.replace(/[^a-zA-Z0-9]/g, ''); 使用javascript函数,
'=--satya','=---satya1','=-----satya2'.
现在我的问题是我必须删除这些特殊字符并像这样打印字符串
'satya'
'satya1'
'satya2'
请帮助解决此问题?使用javascript函数,该函数可帮助您在这种情况下使用正则表达式
var string = '=---satya1';
string = string.replace(/[^a-zA-Z0-9]/g, '');
使用javascript函数,它可以帮助您在这种情况下使用正则表达式
var string = '=---satya1';
string = string.replace(/[^a-zA-Z0-9]/g, '');
您可以使用正则表达式提取该信息,例如
/\'\=-{0,}(satya[0-9]{0,})\'/
实例:
正则表达式匹配
文字”
文字
=
零个或多个
-
启动捕获组并捕获
-文字
satya
-零个或多个
数字
结束捕获组
文字
”
然后使用如下代码
var regex = /\'\=-{0,}(satya[0-9]{0,})\'/g;
while( (match = regex.exec("'=--satya','=---satya1','=-----satya2'")) !== null)
{
// here match[0] is the entire capture
// and match[1] is tthe content of the capture group, ie "satya1" or "satya2"
}
请参阅实时示例的更多详细信息。您可以使用正则表达式(如
/\'\=-{0,}(satya[0-9]{0,})\'/
实例:
正则表达式匹配
文字”
文字
=
零个或多个
-
启动捕获组并捕获
-文字
satya
-零个或多个
数字
结束捕获组
文字
”
然后使用如下代码
var regex = /\'\=-{0,}(satya[0-9]{0,})\'/g;
while( (match = regex.exec("'=--satya','=---satya1','=-----satya2'")) !== null)
{
// here match[0] is the entire capture
// and match[1] is tthe content of the capture group, ie "satya1" or "satya2"
}
请参阅实时示例的更多详细信息。使用:
替换所有非字母和非数字字符或
s.replace(/[-=]/g, '');
要删除所有-
和=
字符,甚至
'=---satya-1=test'.replace(/(=\-+)/g, ''); // out: "satya-1=test"
要防止进一步删除-
或=
请使用:
替换所有非字母和非数字字符或
s.replace(/[-=]/g, '');
要删除所有-
和=
字符,甚至
'=---satya-1=test'.replace(/(=\-+)/g, ''); // out: "satya-1=test"
为了防止进一步删除
-
或=
类似的内容:str.replace(/(=|-)*/,“”)类似的内容:str.replace(/(=|-)*/,“”)