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.
You are using word boundaries \b. To capture something like
NFkappaByou need to remove that restriction.Now this obviously will capture anything like
alphagammakappaso unless there are specific rules for capturing capturing things likeNFkappaB(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.