I have a scenario where i want to match specific word and then match everything until i get another pattern. For example
ABC=145865865
Then anything comes in ways
and then
Date=11/11/2001
I have tried (.*?) but it only match that specific line in my scenario i have multiple lines of data in between.
How can i do this?
Closest guess to what I think you're looking for:
ABC=(\d+)[\s\S]*?Date=(\d\d/\d\d/\d{4})
This uses [\s\S]
which means "either a whitespace character or not a whitespace character", which is equivalent to "any character". The .
can also be set to match any character, but I tend to prefer [\s\S]
because it does just that without having to set flags. You haven't specified the language you are using so I can't tell you how to set such a flag anyway (it's re.DOTALL
in Python).
Multiple lines? If you mean you have newline characters (\n) in between then you need to set the DOTALL flag, as follows:
Pattern p = Pattern.compile(<your-regex-here>, Pattern.DOTALL)
The above will match new line characters between the two strings.