I would like to extract sub-string between certain two words using java.
For example:
This is an important example about regex for my work. >
This is an important example about regex for my work.
Your regex is "an\\s+(.*?)\\s+for". It extracts all characters between an and for ignoring white spaces (\s+). The question mark means "greedy". It is needed to prevent pattern .* to eat everything including word "for".
an\\s+(.*?)\\s+for
\s+
.*