Regex problem in Java in code sample
- by JaneNY
I have job with regex in my expressions: example !(FA1_A.i & FA1_M.i)
I have operators ! ( ) & |
operands have names [a-zA-Z_]*.[a-zA-Z_]
I wrote in Java to split on tokens, but it doesn't split on operators and operands If should be !, (, FA1_A.i, &, FA1_m.i, ) . Can anybody tell me what is wrong ?
String stringOpеrator = "([!|&()])";
String stringOperand = "(([a-zA-Z_]*)\\.([a-zA-Z_]*))";
String reg=stringOpеrator+"|"+stringOperand;
Pattern pattern = Pattern.compile(reg);
Matcher m = pattern.matcher(expression);
// System.out.println("func: " + function + " item: " + item);
while (m.find()) {
int a=m.start();
int b=m.end();
String test=expression.substring(m.start(), m.end());
String g=test;
tokens.add(new Token(expression.substring(m.start() , m.end())));
//m = pattern.matcher(expression);
}