Regex match words Java
This regular expression can be used to validate that a given string contains only characters in it or extract two words from a given string.
Simple word match
The regular expression to match only words looks like this (including compound words):
Test it!
/^\b(?:\w|-)+\b$/
True
False
Enter a text in the input above to see the result
Example code in Java:
Test it!
True
False
Enter a text in the input above to see the result
Test it!
True
False
Enter a text in the input above to see the result