Jump to content

Can't figure this out


ballhogjoni
Go to solution Solved by .josh,

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

Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.