Is valid identifier?
Given a string, determine if it's a valid identifier.
Here is the syntax for valid identifiers:
- Each identifier must have at least one character.
- The first character must be picked from: alpha, underscore, or dollar sign. The first character can not be a digit.
- The rest of the characters (besides the first) can be from: alpha, digit, underscore, or dollar sign. In other words, it can be any valid identifier character.
Examples of valid identifiers:
- i
- wo_rd
- b2h
Examples of invalid identifiers:
- 1i
- wo rd
- !b2h
using System;
using System.Text.RegularExpressions;
public class IdentifierChecker
{
public static bool IsValid(string input)
{
string pattern = @"^[A-Za-z_$][\w_$]+$";
Regex regex = new Regex(pattern);
return regex.IsMatch(input);
}
}
^...$开头和结尾
[A-Za-z_$] 第一个字符的可选范围
[\w_$]后续字符的可选范围
+ 一个或多个重复
| One or more repetitions |
Is valid identifier?的更多相关文章
- IZ65534: 'JAVA.LANG.CLASSFORMATERROR' ERROR FOR A VALID IDENTIFIER
PAR status Closed as program error. Error description Error Message: The java class could not be loa ...
- BASH SHELL not a valid identifier
解决BASH SHELL脚本报错 ‘: not a valid identifier当在shell编辑脚本时,运行时出现了" ‘: not a valid identifier " ...
- iOS 真机测试错误“The application bundle does not contain a valid identifier”
iOS 真机测试错误"The application bundle does not contain a valid identifier" 真机测试的时候报错:"The ...
- bash: export: “path” not a valid identifier [closed]
export SPARK_HOME=/usr/local/spark export PATH=$PATH:$SPARK_HOME/bin bash: export: “path” not a vali ...
- centos6环境远程执行shell脚本报错not a valid identifier的问题处理
# 通过jenkins的apache用户rsync同步php代码到远程服务器报错如下: SSH: EXEC: STDOUT/STDERR from command [/bin/sh /usr/loca ...
- sqlserver the name is not a valid identifier error in function
参考资料:https://stackoverflow.com/questions/22008859/the-name-is-not-a-valid-identifier-error-in-functi ...
- 关于启动bash提示‘bash: export: `//这是新的': not a valid identifier’的解决办法
学习linux以来将centos改的也不少了,也不知道这个问题是由于那个修改来的.最近改bash的操作环境配置文件,用到了~/.bashrc这个文件,发现里面被我修改过. 那是当年安装fcitx输入法 ...
- Python基础(二)
本章内容: Python 运算符(算术运算.比较运算.赋值运算.逻辑运算.成员运算) 基本数据类型(数字.布尔值.字符串.列表.元组.字典.set集合) for 循环 enumrate range和x ...
- linux java 版本
之前linux已经安装了1.6的版本, 我想要升级,于是安装了1.7, /etc/profile 的最后几行是这么写的: JAVA_HOME=/usr/java/jdk1.7.0_79JRE_HOME ...
随机推荐
- 【BZOJ】【1150】【CTSC2007】数据备份Backup
堆/贪心 一共N-1个元素……用堆维护最大值,取了第x个元素以后,插入v[x-1]+v[x+1]-v[x]这个元素,如果再取这个新元素就表示不取x,而取x-1和x+1……大概就是这种“带反悔”的思路吧 ...
- 【BZOJ】【1019】【SHOI2008】汉诺塔
递推/DP 类似普通汉诺塔的一个递推(模拟?$10^{18}$没法模拟吧…… 题解:http://blog.csdn.net/regina8023/article/details/43016813 因 ...
- 剑指offer--面试题23
//该题原本想用递归实现,但却用循环实现了... //关键用了个队列 #include <queue> void Print(BinaryTreeNode* pRoot, std::que ...
- [剑指OFFER] 数组中的逆序对
题目描述 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数. 分析:利用归并排序的思想,分成2部分,每一部分按照从大到 ...
- .net深入体验与实战精要--ASP.NET开发大杂烩(转)
转自:http://www.cnblogs.com/sunhan/p/3371337.html 正巧今天遇到一个获取动态生成table中的一个动态生成的TextBox的值的时候总是findcontro ...
- 用HAProxy和KeepAlived构建高可用的反向代理
用HAProxy和KeepAlived构建高可用的反向代理 用HAProxy和KeepAlived构建高可用的反向代理 前言对于访问量较大的网站来说,随着流量的增加单台服务器已经无法处理所有的请求 ...
- List Comprehensions
看Python高级编程时有几个东西要记一记,方便以后查询 以下代码基本全摘自Python高级编程 取0~9之间的偶数,类C语言写法: 使用list comprehensions可以极大程度上简化语法: ...
- ID3决策树---Java
1)熵与信息增益: 2)以下是实现代码: //import java.awt.color.ICC_ColorSpace; import java.io.*; import java.util.Arra ...
- oracle impdp的table_exists_action详解
oracle impdp的table_exists_action详解 分类: [oracle]--[备份与恢复]2012-01-06 22:44 9105人阅读 评论(0) 收藏 举报 tableac ...
- visual studio 2012 Github
前言 一直以来都想使用Git来管理自己平时积累的小代码,就是除了工作之外的代码了.有时候自己搞个小代码,在公司写了,就要通过U盘或者网盘等等一系列工具进行Copy,然后回家才能继续在原来的基础上作业. ...