Regex extract parts of text after a string is matched

1.7k Views Asked by At

I have string field "event=[someevent1] ID=[000001] text=[Sample Text 123]"

I need just the part inside text that is Sample Text 123

How to extract this using regex?

I have tried (text=).\*$ but this doesn't work.

1

There are 1 best solutions below

0
On

You can use

text=\[([^\]\[]*)

See this regex demo.

Details:

  • text=\[ - a text=[ substring
  • ([^\]\[]*) - Group 1: zero or more chars other than square brackets.

A variation of the pattern with a lookbehind:

(?<=text=\[)[^\]\[]+

It matches one or more chars other than square brackets after text=[ string.