I would like to validate the DNF (Disjunctive normal form) which looks like this A*B+A'*C+C*D*E'. For this purpose, I use the folloing following pattern:
/[A-Z]'?(\*[A-Z]'?)*(\+[A-Z]'?(\*[A-Z]'?)*)+/g
I have tested this pattern using javascript test() method in this online tool:
http://www.pagecolumn.com/tool/regtest.htm and it gives me the result I have expected.
I tried to test the pattern with javascript, using the following code:
<script type="text/javascript">
var dnf="A*3+A*B+CD";
var pattern= /[A-Z]'?(\*[A-Z]'?)*(\+[A-Z]'?(\*[A-Z]'?)*)+/g;
var flag = false;
flag=pattern.test(dnf);
console.log(flag);
</script>
The problem is, I don’t understand, why flag (in this code) become “true”, which has to be “false” cause the terms A*3 and CD in the dnf="A*3+A*B+CD".
I have testet this in the online tester and it says: no matches, what I think is right.
I think you must have entered this into the online tester incorrectly, because I tried the same thing and it is matching
"A*B+C"from the string"A*3+A*B+CD":If you only want to match if the entire string matches your pattern, add start and end of string anchors: