Pergunta

Please find the relevant snippets of my code below:

public static final String GREEK = "(alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega)";

public static int setHasGreek(String str) {
    if (str.toLowerCase().matches(".*\\b"+GREEK+"\\b.*")) return 1;
    return 0;
}

The function works fine if the string is just the Greek string (like "gamma", or "delta", etc), however if my string is "NFkappaB" it doesn't work. Could someone offer advice with modifications to the regular expression?

Thank you.

Foi útil?

Solução

You are using word boundaries \b. To capture something like NFkappaB you need to remove that restriction.

if (str.toLowerCase().matches(".*"+GREEK+".*")) return 1;

Now this obviously will capture anything like alphagammakappa so unless there are specific rules for capturing capturing things like NFkappaB (such as starting with 2 letters and ending in 1) then there is little you can do without a complex regex involving lookarounds to avoid that.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top