Hi.
I have filenames that follow a certain pattern, but aren't always the same number of characters long. I wondered how it is possible to extract each part of the filename.
For example:
M&N C-3456 Cutomer Name REVA 101234A1
where:
M&N = Constant company name (won't change)
C-3456 = Job Number
Customer Name = Self-Explanatory, indefinite length and number of words
**REVA = Revision Number (i would only need the A part)
**101234A1 = Main company job number (101234) and Add-on number (A1, also not always present when job number is)
** not always present
I was thinking if only wcmatch returned the exact strings it found to match the wildcard patterns I would be in business. I'm guessing theres something obvious i'm not getting.
Extract them into a list?
(parse "M&N C-3456 Cutomer Name REVA 101234A1" (chr 32))
; creates multiple strings from a single string ; [s] - string, string to breakdown ; [d] - string, separator ; return: list of strings (defun parse (s d / i l tmp rtn) (cond ((/= "" d) (setq l (strlen d)) (while (setq i (vl-string-search d s)) (setq tmp (substr s 1 i)) (setq rtn (cons tmp rtn)) (setq s (substr s (1+ (+ l (strlen tmp))) (strlen s))) ) (vl-remove "" (reverse (cons s rtn))) ) (t s) ) )
As a start, Search this Forum for things like "split string" or "subdivide string", and you'll find quite a number of routines that can take a string and break it into pieces around whatever delimiting character(s) you want [in this case, the space between each piece]. I think most of them will put the separate pieces into a list of text strings, but some may do different things with them. When they're in a list, if the pieces always come in the same order, you could get [for example] the job number from the list with (nth) or (cadr). You could extract the A off the end of "REVA" using (substr). What you do with the Main Company job number and add-on would depend on certain things [e.g. is the number part before the add-on always the same number of characters long?], but ways can be worked out to determine whether or not there's an add-on, and/or to separate the number from the add-on, if such things are needed.
@mnorthcott wrote:
.....
**REVA = Revision Number (i would only need the A part)
**101234A1 = Main company job number (101234) and Add-on number (A1, also not always present when job number is)
** not always present
And if it is present does it always start with the word REV?
And if is present does it always start with a number? or are any chararacter to indicate that it is present?
Main company job number can be present even without the REV?