This first removes all non-letter characters, folds to lowercase, then splits the input, doing all the work in a single line:
String[] words = instring.replaceAll("[^a-zA-Z ]", "").toLowerCase().split("\\s+");
Spaces are initially left in the input so the split will still work.
By removing the rubbish characters before splitting, you avoid having to loop through the elements.
Related Posts:
- How can I remove punctuation from input text in Java?
- How to replace ” \ ” with ” \\ ” in java
- Using or ‘|’ in regex [duplicate]
- How can I exclude one word with grep?
- Change date format in a Java string
- Split string on whitespace in Python
- Regex how to match an optional character
- What does regular expression \\s*,\\s* do?
- Java; String replace (using regular expressions)?
- Regular Expressions on Punctuation
- How to extract a substring using regex
- Regular expression – starting and ending with a character string
- How to use regex in String.contains() method in Java
- Regex empty string or email
- OR condition in Regex
- How to format strings in Java
- How to convert a char to a String?
- Regex not operator
- Reverse a string in Java
- Convert String to double in Java
- Java String new line
- How to check if a String contains another String in a case insensitive manner in Java?
- Java split string to array [duplicate]
- How to match “any character” in regular expression?
- How to replace � in a string
- What are all the escape characters?
- python re.split() to split by spaces, commas, and periods, but not in cases like 1,000 or 1.50
- Regular expression negative lookahead
- Regular Expressions: Is there an AND operator?
- How to split a String by space
- Regular Expression.how to add optional character at end of regex
- Regular Expression with wildcards to match any character
- How to find all occurrences of a substring?
- How to remove single character from a String
- How to parse this string in Java?
- How to match “any character” in regular expression?
- Python string.replace regular expression
- How to split a string in Java
- Convert character to ASCII numeric value in java
- A regular expression to exclude a word/string
- How to convert a Binary String to a base 10 integer in Java
- Left Hand Side of an Assignment must be a Variable CharAt
- How to capitalize the first letter of a String in Java?
- Using the star sign in grep
- Regex optional group
- std::string formatting like sprintf
- In Java, how to append a string more efficiently?
- Explain the use of a bit vector for determining if all characters are unique
- Convert java.util.Date to String
- Remove all special characters, punctuation and spaces from string
- How can I output only captured groups with sed?
- How to negate specific word in regex?
- Sort a single String in Java
- What is Java String interning?
- What is Java String interning?
- Which regular expression operator means ‘Don’t’ match this character?
- How can I match a string with a regex in Bash?
- Range of valid character for a base 64 encoding
- How to replace a whole line with sed?
- Validate phone number with JavaScript
- Regex to match only uppercase “words” with some exceptions
- How to sort an array of objects in Java?
- How to compress a String in Java?
- java.lang.NumberFormatException: empty String
- How to check if a String is numeric in Java
- List of all special characters that need to be escaped in a regex
- Regex to match only letters
- Finding the complement of a DFA?
- How can I extract a number from a string in JavaScript?
- Java end of file
- Unclosed Character Literal error
- Regular expressions in C: examples?
- How to ignore whitespace in a regular expression subject string?
- Add String Array to ArrayList
- StringIndexOutOfBoundsException String index out of range: 0
- difference between equals() and hashCode()
- How can I check if a single character appears in a string?
- Difference between String replace() and replaceAll()
- Replace a character at a specific index in a string?
- Is there an equivalent to the Scanner class in C# for strings?
- How to convert a String to CharSequence?
- How do I convert a String to a BigInteger?
- Using regex to match any character except =
- How to format a string as a telephone number in C#
- How to convert a String into an ArrayList?
- Regex that matches integers in between whitespace or start/end of string only
- Regular Expressions- Match Anything
- How do I get the last character of a string?
- Cannot invoke toString() on the primitive type int
- How to compare character ignoring case in primitive types
- Escaping Parentheses in Regex
- Append a single character to a string or char array in java?
- How to replace a string in an existing file in Perl
- convert string to arraylist
in java - How to insert multiple tabs string in java?
- Why cannot cast Integer to String in java?
- Split string into array of character strings
- Quotation marks inside a string
- In Java, how do I parse XML as a String instead of a file?
- How to set up redirects for category paginated pages after adding /category/ to permalink