I want to find the words that start with a \"#\" sign in a string in java. There can be spaces between the sign and the word as well.
The string \"hi #how are # yo
\"hi #how are # yo
Use #\s*(\w+) as your regex.
#\s*(\w+)
String yourString = "hi #how are # you"; Matcher matcher = Pattern.compile("#\\s*(\\w+)").matcher(yourString); while (matcher.find()) { System.out.println(matcher.group(1)); }
This will print out:
how you