I need the following function to check a string if it looks like this:
- Any digit (including fraction and decimal)
- optional one of the synonyms of pieces / bags / boxes
- optional one of the male / female synonyms
there can be a space between each, and the order of 2 optional parts should not matter ("2 box male" == "2 male box")
but instead of doing something useful, this function excludes everything that starts with a digit:
Function validAmount(Zelle As Variant) Set regEx = CreateObject("VBScript.RegExp") regEx.IgnoreCase = True regEx.Pattern = "\d\s?(pcs|pieces|piece|pc|stk|bags|bag|box|bx|boxes)?\s?(male|m|female|f)?" If (regEx.test(Zelle)) Then validAmount = True Else validAmount = False End If End Function
I hope my mistake is not too stupid.
edit I thought of an extra feature. how can I allow several objects of the template above, separated by the symbol ",", like "1 boxing woman, 3 bags of m, 4pcs of male"
ps: both solutions work very well, but allow something like this "1 male female" or "2 boxed bag"
edit2: first of all: I am very grateful for your help! I would never decide it myself! and I wanted to click "allow" (I can not press "up" because my reputation is still too low), as soon as everything works as planned. If I had to click on it earlier, I'm sorry. His first question is here, and I'm a little overwhelmed by how quickly your answers arrive :)
I think I can not express my wishes: D is very sorry! here is the third attempt: only (at least) one of each group should be allowed. the true source data should be: "# box gender" "# gender box" "# box" "# Gender" "#" but not: "# box gender" or "# gender gender"
@sln: I think your first look is more like me, but it allows you to use two instances of the same group, even if it is looking for me, since it should not :( (the same for JMax solution)
@JMax: I like your "split" solution! havent even thought about this simple trick: D I was so fixed in regular expression that I was thinking about something else