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?的更多相关文章

  1. 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 ...

  2. BASH SHELL not a valid identifier

    解决BASH SHELL脚本报错 ‘: not a valid identifier当在shell编辑脚本时,运行时出现了" ‘: not a valid identifier " ...

  3. iOS 真机测试错误“The application bundle does not contain a valid identifier”

    iOS 真机测试错误"The application bundle does not contain a valid identifier" 真机测试的时候报错:"The ...

  4. 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 ...

  5. centos6环境远程执行shell脚本报错not a valid identifier的问题处理

    # 通过jenkins的apache用户rsync同步php代码到远程服务器报错如下: SSH: EXEC: STDOUT/STDERR from command [/bin/sh /usr/loca ...

  6. 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 ...

  7. 关于启动bash提示‘bash: export: `//这是新的': not a valid identifier’的解决办法

    学习linux以来将centos改的也不少了,也不知道这个问题是由于那个修改来的.最近改bash的操作环境配置文件,用到了~/.bashrc这个文件,发现里面被我修改过. 那是当年安装fcitx输入法 ...

  8. Python基础(二)

    本章内容: Python 运算符(算术运算.比较运算.赋值运算.逻辑运算.成员运算) 基本数据类型(数字.布尔值.字符串.列表.元组.字典.set集合) for 循环 enumrate range和x ...

  9. linux java 版本

    之前linux已经安装了1.6的版本, 我想要升级,于是安装了1.7, /etc/profile 的最后几行是这么写的: JAVA_HOME=/usr/java/jdk1.7.0_79JRE_HOME ...

随机推荐

  1. poj 1815 Friendship 字典序最小+最小割

    题目链接:http://poj.org/problem?id=1815 In modern society, each person has his own friends. Since all th ...

  2. TGL站长关于常见问题的回复

    问题地址: http://www.thegrouplet.com/thread-112923-1-1.html 问题: 网站配有太多的模板是否影响网站加载速度 月光答复: wp不需要删除其他的模板,不 ...

  3. 拆分Sql列中内容的拆分

    拆分Sql列中内容的拆分. /*按照符号分割字符串*/ create function [dbo].[m_split](@c varchar(2000),@split varchar(2)) retu ...

  4. PC和移动端浏览器同步测试工具Browsersync使用介绍

    在移动端网页开发中,总是因为不方便调试,导致各种问题不容易被发现.但是现在有了Browsersync,一切都解决了. 不熟悉的同学可以看看Browsersync的官方网站Browsersync中文网. ...

  5. ExtJS与jQuery的一点细节上的对比

    首先说明这不是一篇完整解读ExtJS和jQuery所有方面差异的文章,只是针对我个人刚看了两天的jQuery产生的一些疑问的整理.之前用过一段时间ExtJS,了解ExtJS的一些机制.现在做移动开发, ...

  6. (转)STL中set的用法

    转载自here 1.关于set map容器是键-值对的集合,好比以人名为键的地址和电话号码.相反地,set容器只是单纯的键的集合.例如,某公司可能定义了一个名为bad_checks的set容器,用于记 ...

  7. 知问前端——概述及jQuery UI

    知问系统,是一个问答系统.主要功能:即会员提出问题,会员回答问题.目前比较热门的此类网站有:知乎http://www.zhihu.com.百度知道http://zhidao.baidu.com等.这里 ...

  8. CSS深入理解之line-height

    以下文字整理自慕课网——张鑫旭的<CSS深入理解之line-height>. line-height,又称行高,指的是两行文字基线之间的距离,又可以称为这行文字所占的高度. 定义三问: 什 ...

  9. SSH 使用JUnit测试

    前提是引入两个包:org.springframework.test-3.1.3.RELEASE和JUnit4. package com.qk.test; import javax.annotation ...

  10. ios开发与安卓开源项目及库

    自己总结的iOS.mac开源项目及库 https://github.com/Tim9Liu9/TimLiu-iOS 自己总结的Android开源项目及库 https://github.com/Tim9 ...