Jump to content

Can't figure this out


ballhogjoni

Recommended Posts

\w is shorthand for a "word" character class, and is the equivalent of [a-z0-9_] which matches letters, numbers or underscore. It stops at "DD" because a hyphen isn't a "word" character.

 

A liberal approach would be to do this:

 

 

/SKU:\s(\S+)/

 

This will capture anything that is not a space.

 

A more restrictive approach could be this:

 

/SKU:\s(\w+-\w+)/

 

This will match one or more "word" characters followed by a hyphen followed by one or more "word" characters.

 

An even more restrictive approach could be this:

 

/SKU:\s(\w+-\d+)/

 

This will match one or more "word" characters followed by a hyphen followed by one or more numbers.

 

An even more restrictive approach could be this:

 

/SKU:\s([A-Z]{2}-\d{6})/

 

This matches for 2 uppercase letters followed by a hyphen followed by 6 numbers

Okay, then you can use the first pattern I showed:

 

/SKU:\s(\S+)/

 

As I said, this will capture anything that is not a space.

 

A more restrictive version based on your feedback could be:

 

/SKU:\s([\w-]+)/

 

This will capture one or more "word" characters or hyphens

 

But "word" characters include underscore, so even more restrictive would be:

 

/SKU:\s([a-z0-9-]+)/i

 

 

This will explicitly only match letters, numbers and hyphens. Notice I added the "i" on the end of there, after the closing delimiter. This is to make the match case-insensitive

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.