1. Re PATTERN.E (to David)
I've read in a whole file. Now I want to get the version string out of it.
Usually it is something like
v1.0 (c) Copyright Language Project, 2000
However it can be v1.1.1 or V1.23{MR} and the (c) can be (C) and the owner can
be different
If I just want the numbers...
If I want the v|V and the numbers...
If I want the whole shebang...
.. what do I need to specify using pattern()?
Zaph
2. Re: Re PATTERN.E (to David)
"Zaphod Beeblebrox" wrote:
> v1.0 (c) Copyright Language Project, 2000
The (c) brings up a problem: the paren characters are reserved. I'll post a
fix to Robert this evening.=. The '/' should be used to specify a literal
value for a special character. For example:
/((C|c)/)(.*)
Broken down into parts: The pattern:
/(
specifies the literal '('; the pattern:
(C|c)
specifies an upper or lower case 'c', and the pattern:
/)
specifies a literal ')'. The pattern:
(.*)
matches the rest of the pattern until the end of the line, and groups the
result into the second argument returned from the pattern matcher.
Matching the version is a bit problematic, in that it can get a lot of false
matches. The 'version' text can possibly look like any of the following:
v
v.
ver
ver.
version
You can specify these with something like this:
(version|ver.|ver|v.|v)
Note that the order of matching is important here - you want to check for
'version' before you check for 'ver', or you will end up with 'sion' as part
of the matched string. You can move the '.' out of the pattern with:
(version|ver|v)[.]?
Also note that the pattern is case sensitive, so Ver and VERSION won't
match. So you need to add these, or set the string to lower case before
performing the match:
(VERSION|Version|version|VER|Ver|V|v)[.]?
Now you need to specify the version string. This can include any number of
alphanumeric and '.' characters:
[a-zA-Z0-9.]*
it might be easier to specify that it's terminated by a non-space:
[^ ]*
There is possibly a space between the version and the number:
(VERSION|Version|version|VER|Ver|ver|V|v)[.]?[ ]?[^ ]*
Unfortunately, this matches against the string:
"this is very silly"
So you may decide that the keys need to be tightened up. If they wrote
something like:
version 1.0 pre-alpha
then the 'pre-alpha' will not be matched, because it's delimited by a space.
> If I just want the numbers
Use parens to indicate the portion that you care about:
(VERSION|Version|version|VER|Ver|ver|V|v)[.]?[ ]?([^ ]*)
The second set of parens specifies the version number.
> If I want the v|V and the numbers...
You can nest parens. The first set of parens contains the value:
((VERSION|Version|version|VER|Ver|ver|V|v)[.]?[ ]?[^ ]*)
> If I want the whole shebang...
If the pattern returned false, you know you didn't get a match.
Hope this helps!
-- David Cuny
3. Re: Re PATTERN.E (to David)
Thus spake "Cuny, David" on Thu, 3 Feb 2000:
>Hope this helps!
It helps heaps, thanks very much.
Zaph.