0

I have bunch of product codes that I'm trying to parse (Example 99 ITEM SEC SALE). In rare conditions, product codes are like 99 ITEM SEC SALE.

If it the cell is "99 ITEM SEC SALE" then "ITEM SEC" will be parsed (take out 99 and SALE). If the cell is "99 ITEM SEC" (NO--> SALE,SOLD, OR PURCHASED). I want ITEM SEC will be parsed as well.In other words, "SALE SOLD AND PURCHASED" are prohibited words.

1-It always starts with a set of numbers (no limit) 2-Alphabetic characters (Any) 3-Alphabetic characters (any)-optional 4-If the ending value(string) is NOT "SALE" or "SOLD" or "PURCHASED" then take the digits out and parse

I found something similar but could not figure out how it should work for my case.

Thanks for the help

1 Answer 1

0

Okay, so what you're working for is something like this.

(?P<number>\d+)\s+(?P<Item_Name>\w+)\s+(?P<code>[a-zA-Z]{0,3})\s+(?P<status>SOLD|SALE|PURCHASED)?

(?P<number>\d+) -- Named Capture Group 1 (number)- Match any number
\s+ -- Match any number of spaces
(?P<Item_Name>\w+) -- Named Capture Group 2 (Item_Name) - Match any word until space
\s+ match any number of spaces
(?P<code>[a-zA-Z]{0,3}) -- Named Capture Group 3 (code) - Match any a-zA-Z character 0-3 times
\s+ match any number of spaces
(?P<status>SOLD|SALE|PURCHASED)? -- Named Capture Group 4 (status) - Match SOLD / SALE / PURCHASED (? means 0 or 1 times so this is optional)

Live example: https://regex101.com/r/oR3sK8/1

I don't recall if named capture groups work like this for objective-C, if they don't you can remove the ?P<...> and the regex should still operate without issues (and keep your capture groups largely unchanged).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.