Java tutorial
//package com.java2s; //License from project: Apache License public class Main { /** * @param source * @return Identifier that stands for tag name or tag attribute at the start * of specified string. */ public static String getIdentifier(String source) { if (source.length() == 0) { return null; } StringBuilder buffer = new StringBuilder(); int index = 0; int len = source.length(); boolean charOk; do { char ch = source.charAt(index); charOk = (index == 0 && Character.isJavaIdentifierStart(ch)) || (Character.isJavaIdentifierPart(ch) || ch == '-' || ch == ':' || ch == '.'); if (charOk) { buffer.append(ch); } index++; } while (charOk && index < len); String identifier = buffer.toString(); return identifier.length() > 0 ? identifier : null; } }