Regex problem in Java in code sample
Posted
by
JaneNY
on Stack Overflow
See other posts from Stack Overflow
or by JaneNY
Published on 2011-01-05T14:06:19Z
Indexed on
2011/01/05
14:53 UTC
Read the original article
Hit count: 395
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);
}
© Stack Overflow or respective owner