i am trying to validate a custom expression. This expression contains the follow conditions:
- Number position;
- Type operation;
- Expression;
- Alias (optional);
- Comment (optional);
The conditions are separated by “|” pipe. So, four pipes is the limit.
So, to be a valid expression:
0|S|write(&var1)|alias1|my coment – OK
0|K|write(&var1)|alias1|my coment – FAIL
1|I|read(&var2)|alias2| – OK
1|S|read(&var1)|| – OK
2|N|if(&var1 == &var2);read(&var3)|| – OK
3|S||| – FAIL
3|I|write(&var1)|alias 3| – FAIL
3|N|write(&var1)|alias1|my coment| – FAIL
I am using this ER to validate:
^(\d{1,10})\|(S|M|I|N)\|(.+?)\|([a-zA-Z0-9]+)?\|(.+)?
But i can not validate the expression that ends with pipe. Because, in a comment can have any caracter except a pipe…
Some idea??
Thanks
Try using
[^|]instead of(.+)?at the end of your regex:As a side note: for every sub-expression subexpr the following regexes are equivalent:
and