Regex to match text between 9 space characters

Viewed 35

I'd like to capture the text between a fixed number of 9 spaces from a text that looks like this: Demo

     (LD4377) Masinuta clasica din lemn tractor - albastru             1                                                              buc                  3             15.00       45.00                  8.55         - Little Dutch         

What I want to extract: (LD4377) Masinuta clasica din lemn tractor - albastru - Little Dutch

What I'm using: \s{9}((?:(?:[a-z0-9A-Z\-\/()])+[ ]{1})+)\s{9}

Is there a more efficient way to get the desired text? Any help is much appreciated!

1 Answers

You can unroll the loop first repeating only the character class, and then optionally repeat a non capture group with a leading space.

You can replace [ ]{1} with a mere space

\s{9}([a-z0-9A-Z\/()-]+(?: [a-z0-9A-Z-\/()-]+)*)\s{9}

Regex demo

Related