I have following formats of data:
CumulativeReport_cumulativeReportBins_CumulativeBinNetworksViews_totalSuccessfulHeartbeats_1
CumulativeReport_cumulativeReportBins_CumulativeBinNetworksViews_totalSuccessfulHeartbeats__1
I am using following regex:
^(.*)_(.*?_.*?)(_\d$|__\d$)
My requirement every time is to get CumulativeBinNetworksViews_totalSuccessfulHeartbeats. For first case its working fine but for second case its printing "totalSuccessfulHeartbeats_1". How to solve this.
You can use
See the regex demo. Details:
^- start of string(.*)- Group 1: any zero or more chars other than line break chars as many as possible_- an underscore([^_]+_[^_]+)- Group 2: one or more chars other than_,_and one or more chars other than___?- one or two underscores\d- a digit$- end of string.