[no subject]

SNOBOL solves the problem much more simply.

In order to find out which string is matched, a name may be attached to a
pattern. If the pattern matches, the matched substring is assigned as value to
the name. This feature is called value assignment in pattern matching. A name
is attached to a pattern by using the binary assignment operator indicated by
a period. For example

NVOWEL = VOWEL . V

assigns NVOWEL a pattern that matches a vowel. The name V is attached to this
pattern. If the pattern matches, the substring it matches is assigned to V.
For example, if the value of TEXT is "HELLO WORLD", the statement

TEXT NVOWEL

succeeds and the string E is assigned to V

Names may be assigned to components of patterns in as many places as desired.
In this way the substrings matched by different components of the pattern can
be determined. A simple example is

DVOWEL = VOWEL . V1 VOWEL . V2

in which V1 is attached to the first vowel and V2 to the second. If DVOWEL
matches, the individual vowels are assigned to V1 and V2.

Let's see how to express the example shown above where we extract the integer
in a string.

SNOBOL does not use [0-9]+ to represent a series of digits; instead, SNOBOL
uses

SPAN('0123456789')

which matches a contiguous sequence of digits. So, here's how to extract the
integer in TEXT:

TEXT SPAN('0123456789') . V

If the value of TEXT is 'The person put 12 dollars into the jar' then the
value of V is '12'

In my opinion, SNOBOL provides a superior solution to the task of extracting
the substring of TEXT that matches PATTERN.

Current Thread