-2

This is my string:

[TEST1 lorem ipsum123][TEST2 lorem ipsum123][TEST3 lorem ipsum123]Test4

I would like to match [TEST1 lorem ipsum123]. From TEST1 until ] it can be anything.

This is what I have tried

TEST1.+\]

But it will match the string until the last ] character. How can I let it match until the first character instead?

Proseller
  • 113
  • 1
  • 8

2 Answers2

0

Instead of matching anything, use this:

TEST1[^\]]+\]

Máté Juhász
  • 2,197
  • 1
  • 19
  • 40
0

Use this pattern:

\[TEST\d[^[]+\]

Demo

Explanation:

  • \[ - match [ that come before TEST
  • \d - match one digit after TEST
  • [^[] - this match anything except [, so it can match anything until the first ]
  • \] - is for match \] at the end of the match
Alireza
  • 2,103
  • 1
  • 6
  • 19