Extract sub-string between two certain words using regex in java

后端 未结 3 1895
囚心锁ツ
囚心锁ツ 2020-12-30 09:59

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.
         


        
3条回答
  •  难免孤独
    2020-12-30 10:50

    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".

提交回复
热议问题