access vba - What is a Regex equivalent of the 'Trim' function used in languages such as VB and Java..? -
i'm using regex in microsoft access 2007 database vba project reference microsoft vbscript regular expressions 5.5.
all well...mostly. know regular expression act 'trim' function..? (remove leading , trailing spaces)
i have this: ((?:.?)*) "capture after last match". matches spaces remove.
below relevant code, followed screenshot of debugger. item 4 in submatches has " can". how remove space regex, don't have use trim function..?
pattern = "^(\d{1,2})(?:\/)(\d{1,2}(?:\.\d{1,3})?)(oz)((?:.?)*)" regex.pattern = pattern set matchcollection = regex.execute(workstring) if matchcollection.count > 0 matchsection = "loose cases" itemtype = "case" percase = matchcollection(0).submatches(0) perpack = 1 unitsize = matchcollection(0).submatches(1) uom = matchcollection(0).submatches(2) other = vba.trim(matchcollection(0).submatches(3)) end if
ok, figured out. reiterate (and clarify): original regex ((?:.?)*) meant "capture left after last match". captured leading & trailing spaces.
removing leading spaces easy, every attempt remove trailing spaces foiled * in group. read \b , dropped 1 in , works.
this have now: (?: ?)((?:.?)*)\b(?: *) "match left after last match, except leading or trailing spaces".
and in context, whole of it...
(\d{1,2})/(\d{1,2})pk-(\d{1,2}(?:.\d{1,3})?)(oz|ml)(?: ?)((?:.?)*)\b(?: *)
which meant match on string such this...
2/12pk-11.125oz can ret
...which describes cases of beer in our warehouse. =-)
Comments
Post a Comment