antonweld
antonweld

Reputation: 11

Regex match everything up until specific number + character sequence

I am trying to match on product titles up until their pack size.

Examples:

To return:

Matching on numbers using [^0-9]* does not take into account names including numerical values.

Is there a [^0-9]* AND (g|l| Pack) combo i could use?

Upvotes: 1

Views: 153

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521249

You could use the following regex pattern:

^.*(?=\s+\d+\w*(?: \w+)?$)

Demo

This regex pattern says to match:

^.*                      all content from the start
(?=\s+\d+\w*(?: \w+)?$)  until hitting a number with optional trailing
                         word characters, followed by space and optional unit,
                         at the end of the input

Upvotes: 1

Related Questions