-1

In this string:

<@edi:outOperatorVoyageNbr>V4</@edi:outOperatorVoyageNbr>

I would like to match:

<@edi:

But this gets matchedinstead :

<@edi:outOperatorVoyageNbr>V4</@edi:

This is the regex I have tried already:

<@.*(:+?)

But it isnt working :(

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Robin Medland
  • 124
  • 1
  • 4
  • 19
  • 3
    You’re nearly there with the non-greedy `+?`, but you’ve applied it to the wrong part of the pattern. The `.*` still matches more than you want it to. – Biffen Jan 11 '19 at 10:14
  • Does this answer your question? [Regular expression to stop at first match](https://stackoverflow.com/questions/2503413/regular-expression-to-stop-at-first-match) – Ryszard Czech Dec 06 '21 at 22:52

1 Answers1

1

Here is one option:

<@[^:]+:

This matches <@, followed by one more non colon characters, then followed by the first colon.

Demo

You could also use a lazy dot here:

<@.*?:

This says to match anything after <@, but stopping before the first colon.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360