0

i am trying a regex to extract the content between ! and |thumbnail!.

I am using [^&]*(!)[^&]*(|thumbnail!)[^&]* to get the content. My pattern is:

Pattern p = Pattern.compile("[^&]*(!)[^&]*(|thumbnail!)[^&]*)",Pattern.DOTALL);

The text can contain any characters including returns, newline and so on. Please assist how I can extract the content. Thanks

Kannan Lg
  • 911
  • 4
  • 11
  • 21
  • Use `"(?s)!(.*?)\\|thumbnail!"` (or if you have `&`-delimited string, replace `.` with `[^&]`). – Wiktor Stribiżew Nov 21 '16 at 07:59
  • @WiktorStribiżew I tried this pattern for this string, it didnt work:

    !Silhouette analysis.png|thumbnail!
    . could you please help?
    – Kannan Lg Nov 21 '16 at 08:22
  • 1
    First of all, [it works](https://regex101.com/r/gequrd/1). Second, see [RegEx match open tags except XHTML self-contained tags](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). – Wiktor Stribiżew Nov 21 '16 at 08:25

0 Answers0