关于正则表达式问题

hbqc_zh 2006-08-18 05:30:06
以下是关于验证正则表达式C#代码:
// JScript 文件chx---2006-05-30
//正则表达试检查输入是否合法
function IsInLaw(txtid)
{
var instr=public_getElementByID(txtid).value;
var str=/[`<>~!@#$%?/;:'""\{\}\[\]\\|,.^&*()\-+=]/
var s1=instr.match(str);
if(s1!=null)
{
window.alert("请不要输入不合法字符!");
public_getElementByID(txtid).value="";
public_getElementByID(txtid).focus();
return false;
}
return true;
}

请问在C++中该怎么写?也就是验证输入的字符串是否包含以下字符
[`<>~!@#$%?/;:'""\{\}\[\]\\|,.^&*()\-+=]
...全文
182 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2006-08-19
  • 打赏
  • 举报
回复
#include<deque>

#include<iostream>

#include<algorithm>

#include<boost/regex.hpp>



int main()

{

using namespace boost;

using namespace std;

regex expression("\\s+href\\s*=\\s*\"([^\"]*)\"",regbase::normal|regbase::icase);

string s="<a href=\"index.html\"><img src=\"logo.gif\"></a>";

deque<string> result;

regex_split(std::back_inserter(result),s,expression);

copy(result.begin(),result.end(),ostream_iterator<string>(cout,"\n"));

int c;

cin>>c;

return 0;

}

cpp里面
「已注销」 2006-08-19
  • 打赏
  • 举报
回复
"[`<>~!@#$%?/;:'\"\"\{\}\[\]\\\\|,.^&*()\-+=]+";
Waiting4you 2006-08-19
  • 打赏
  • 举报
回复
[^`<>~!@#$%?/;:'"\{\}\[\]\\|,.\^&*\(\)\-+=]*
lexchou 2006-08-19
  • 打赏
  • 举报
回复
System.Text.RegularExpressions.Regex.IsMatch(需要检查的字符串,正则表达式)
「已注销」 2006-08-19
  • 打赏
  • 举报
回复
[`<>~!@#$%?/;:'""\{\}\[\]\\|,.^&*()\-+=]{1, }

13,824

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧