I am trying to post an answer on SO but it keeps showing ill-formatted code error. It renders fine in the preveiw though. What's the issue? **Error msg:** >Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon **Answer Text:** <!-- https://stackoverflow.com/q/29783092/10115137 --> As per java package naming *conventions*, the basic syntax - allows only lower case english alphabets,numbers, _ and . - must start with alphabet - can't be malformed eg: contains .. | endsWith . | contains java keywords Ignoring the keyword constraint, the regex can be ^[a-z][a-z0-9_]*(\.[a-z0-9_]+)*[a-z0-9_]*$ //regex breakdown //^[a-z] start with one lowercase english alphabet //[a-z0-9_]* followed by zero or more of alphabets, numbers or _ //(\.[a-z0-9_]+)* zero or more of these // .(one or more of alphabet|number|_) //[a-z0-9_]*$ must end in alphabet|number|or _ [try][1] This differs from @gvalkov's answer by - allowing the number of word.word constructs to be zero - augmenting last char check with * to correctly detect last char even in presence of word.word matches [1]: https://regex101.com/r/wpryj1/3