Note that there are some explanatory texts on larger screens.

plurals
  1. POHard time figuring out the correct regex to match uppercase words
    text
    copied!<p>I have a simple requirement. We use the hibernate validation engine to figure out if a constraint is true or false.</p> <p>True should be a text if all the words starts with an uppercase character. There are some difficulties:</p> <p>Words could also start like this <pre> 8-Test or even 8Test or even (Test) or even -Test or anything comparable </pre> Also usually they are comma separated (or a different separator):<pre> Test, Test, Test </pre> <b>Remember I only want to make sure that words in the String starts uppercase. When you see my tries, probably I am overcomplicating things. </b></p> <p>Here are some samples: Expected to match all (true):<pre> - Hydroxyisohexyl 3-Cyclohexene Carboxaldehyde, Benzyl - Test, Test, Test - CI 15510, Methylchloroisothiazolinone, Disodium EDTA - N/A - NA</pre> Expected to not match all (false):<pre> - hydroxyisohexyl 3-Cyclohexene Carboxaldehyde, Benzyl - Test, test, Test - CI 15510, Methylchloroisothiazolinone, Disodium eDTA - na - n/a</pre> My tries were going into this directions:<pre> <code> final String oldregex = "([\\W]*\\b[A-Z\\d]\\w+\\b[\\W]*)+"; final String regex = "([A-Z][\\d\\w]+( [A-Z][-\\d\\w]+)*, )*[A-Z][-\\d\\w]+( [A-Z][-\\d\\w]+)*\\.";'</code></pre> actually with "<b>oldregex</b>" option I ran into an infinitive calculation for some texts Use this to test regex: <a href="http://gskinner.com/RegExr/" rel="nofollow">http://gskinner.com/RegExr/</a> (without double backslashes of course)</p> <p>Thanks for helping!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload