Quantcast
Channel: Questions in topic: "splunk-enterprise"
Viewing all articles
Browse latest Browse all 47296

Using regex to extract a string where the following string may or may not exist

$
0
0
Hi, I am trying to extract some fields which are generally bound by other strings (eg Some Text 1 Some Text 2). I have a situation where a field may or may not have anything following it. For example, with this data set : 1 Some Text 1 Some Text 2 2 Some Text 1 ", 3 Some Text 1 Some Text 2 4 Some Text 1 Some Text 2 5 Some Text 1 ", This regex partly works in that is extracts correctly items 1, 3, and 4: Some Text 1\s+(?P.+)\s(Some Text 2|\",) This regex partly works in that is extracts correctly items 2 and 5, but extracts the entirety of items 1, 3, and 4. Some Text 1\s+(?P.+)(Some Text 2|\",) The difference is the "\s". I can't seem to include that in the match group, only before it. I am sure I am missing something obvious but can't seem to see it. Any help much appreciated. Thankyou.

Viewing all articles
Browse latest Browse all 47296

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>