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
- How do I convert a String to an int in Java?
- OR condition in Regex
- How to format strings in Java
- Java – Convert integer to string [duplicate]
- How to split a string in Java
- What is a Context Free Grammar?
- How do I compare strings in Java?
- How to convert a char to a String?
- Regex not operator
- How to convert/parse from String to char in java?
- Reverse a string in Java
- What does \’.- mean in a Regular Expression
- Regex not operator
- Reverse a string in Java
- Java String Split by “|”
- Convert String to double in Java
- Java String new line
- How can I validate an email address using a regular expression?
- Regular expression to match a line that doesn’t contain a word
- Regex not operator
- How to check if a String contains another String in a case insensitive manner in Java?
- Java split string to array [duplicate]
- Difference between \b and \B in regex
- How to match “any character” in regular expression?
- String concatenation: concat() vs “+” operator
- How to remove the last character from a string?
- Regex: ignore case sensitivity
- What does the regex \S mean in JavaScript?
- How can I validate an email address using a regular expression?
- Java string to date conversion
- How to replace � in a string
- What are all the escape characters?
- Regex: ignore case sensitivity
- Converting String to “Character” array in Java
- Python regex AttributeError: ‘NoneType’ object has no attribute ‘group’
- Regular Expression for alphanumeric and underscores
- What is the difference between the regular expressions [^\d\s] and [\D\S]
- string to string array conversion in java
- Regular Expression for alphanumeric and underscores
- grep –ignore-case –only
- Regex AND operator
- Best way to convert an ArrayList to a string
- python re.split() to split by spaces, commas, and periods, but not in cases like 1,000 or 1.50
- python re.split() to split by spaces, commas, and periods, but not in cases like 1,000 or 1.50
- Regex to test if string begins with http:// or https://
- Regular expression negative lookahead
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- Regex how to match an optional character
- Regular Expression to match string starting with a specific word
- Regular Expressions: Is there an AND operator?
- Best way to convert an ArrayList to a string
- Writing a very simple lexical analyser in C++
- How to split a String by space
- Regular expression to match standard 10 digit phone number
- Regular Expression.how to add optional character at end of regex
- String interpolation in Java 14 or 15
- Regular Expression with wildcards to match any character
- What is a non-capturing group in regular expressions?
- How to find all occurrences of a substring?
- Understanding regex in Java: split(“\t”) vs split(“\\t”) – when do they both work, and when should they be used
- How to validate an email address in PHP
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- What is a non-capturing group in regular expressions?
- How to remove single character from a String
- Regular expression to match standard 10 digit phone number
- How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops
- Python string.replace regular expression
- Ignoring upper case and lower case in Java
- How to parse this string in Java?
- How to convert any Object to String?
- How to match “any character” in regular expression?
- how to replace quotation marks with \”
- Remove all special characters, punctuation and spaces from string
- This can be done without regex:
- How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops
- Python string.replace regular expression
- How to split a string in Java
- Symbol for any number of any characters in regex?
- Grep and Python
- Regex – Does not contain certain Characters
- Convert character to ASCII numeric value in java
- A regular expression to exclude a word/string
- How to validate an email address in JavaScript
- Using Bash regex match (=~) where regex includes quotes (” characters)
- Illegal Escape Character “\”
- Searching for UUIDs in text with regex