regex: check string for even number of a symbol

Hi,for example "***'asd'asd" is valid, but "asd'asd'asd'asd" is not, for symbol " ' ". I have tried every combination of \w, [...],',+ and nothing...Ideas?
[183 byte] By [uiga] at [2007-11-27 6:19:23]
# 1
i'm not really good in regex, but i think with something like: [^']* any char should be allowed, except " ' "
calvino_inda at 2007-7-12 17:33:54 > top of Java-index,Java Essentials,Java Programming...
# 2

boolean isValid(String s, char symbol) {

return ((s.length() - s.replace(""+symbol, "").length()) % 2) == 0;

}

prometheuzza at 2007-7-12 17:33:54 > top of Java-index,Java Essentials,Java Programming...
# 3

>boolean isValid(String s, char symbol) {

> return ((s.length() - s.replace(""+symbol,

> "").length()) % 2) == 0;

>

what is doing the %2 here, prome' ?

calvino_inda at 2007-7-12 17:33:54 > top of Java-index,Java Essentials,Java Programming...
# 4
> ...> what is doing the %2 here, prome' ?If there are an even number of char symbol in String s, then s.length() - s.replace(""+symbol, "").length() will also be even. So that number mod 2 will equal zero (and return true).
prometheuzza at 2007-7-12 17:33:54 > top of Java-index,Java Essentials,Java Programming...
# 5
looks like i had misunderstood the question ^^
calvino_inda at 2007-7-12 17:33:54 > top of Java-index,Java Essentials,Java Programming...
# 6

If you really have to have a regex solution, this should work: if (str.matches("[^']*+(?:'[^']*+'[^']*+)*+"))

{

// it's good

}

But I like prometheuzz' solution better.

uncle_alicea at 2007-7-12 17:33:54 > top of Java-index,Java Essentials,Java Programming...