Can someone help me with this regex expression. I want to extract first word after Manufacturer Part Number:
, in this case it's laml005
.
The one that nearly does the job is this one: Manufacturer Part Number:(.*)
However, it gets whole line laml005 EAN: 731084217335
, and I just need laml005
.
String:
about the condition\nBrand: mure\nManufacturer Part Number: laml005 EAN: 731084217335
Note that .*
matches any char other than a newline, and *
is a greedy quantifier matching zero or more instances of the construct/symbol before it. So, .*
can't but get you the whole rest of the line.
You can use \S+
to only capture 1 or more non-whitespace symbols, or \w+
to match 1 or more word chars after Manufacturer Part Number:
:
/Manufacturer Part Number:\s*(\S+)/
See this regex demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With