Regex until first occurrence of a characters

Hi All, Could you guys please guide me on using Regex pattern for below type of string.

ST(JKT);ST(HKG);PU(HKG);SI(HKG);RW(HKG) ;WO(KUL<13.400kg><26.0x36.5x28.0cm>) ;ST(HKG);PU(HKG);RW(KUL<4.200kg><3.0x3.0x3.0cm>);ST(HKG);ST(HKG);PU(HKG);SI(HKG);;WO(KUL<28.300kg><3.0x8.0x9.0cm>)

I just wants to strip one those dimension (as bold above) right after the word “;WO” (always) followed by 3 code (which is KUL in this case) and those dimensions followed.
Basically from the ;WO until first occurrence of ;

Sometimes there will be 2 WO in one string and this should output 2 pattern

Expected result:
WO(KUL<13.400kg><26.0x36.5x28.0cm>) — 1st
WO(KUL<28.300kg><3.0x8.0x9.0cm>) ---- 2nd

Really would appreciate your guidance on this.

1 Like

Hi @Serran_Neru

Try it yourself on :slight_smile:

While I am trying it myself

Hope this helps :smiley:


Hi @Shubham_Varshney, Thnaks alot. Actually I’m trying on it, but stucked at getting the first occurrence of >);
This is the pattern i used. (?<=;)WO.+(?=>[)]]:wink: But its match till last

Hi, you need to add a ? next to the + so it is non-greedy.

Maybe something like this, or without the whitespace:

But, you can adjust it for your needs.



Duplicate post @loginerror

Please refer to the answer

1 Like

Hi Serren Neru,

Try to execute this Regex **


** U will get multiple Matches.

:grinning: Regards,