Hi,
�� have you try with ��(World>>Help>>Help Browser>>Regular Expressions Framework>>Usage)
SUBEXPRESSION MATCHES
After a successful match attempt, you can query the specifics of which
part of the original string has matched which part of the whole
expression.
A subexpression is a parenthesized part of a regular expression, or
the whole expression. When a regular expression is compiled, its
subexpressions are assigned indices starting from 1, depth-first,
left-to-right. For example, `((ab)+(c|d))?ef' includes the following
subexpressions with these indices:
1: ((ab)+(c|d))?ef
2: (ab)+(c|d)
3: ab
4: c|d
After a successful match, the matcher can report what part of the
original string matched what subexpression.
And theres an example��
This facility provides a convenient way of extracting parts of input
strings of complex format. For example, the following piece of code
uses the 'MMM DD, YYYY' date format recognizer example from the
`Syntax' section to convert a date to a three-element array with year,
month, and day strings (you can select and evaluate it right here):
| matcher |
matcher := RxMatcher forString: '(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]+(:isDigit::isDigit:?)[ ]*,[ ]*(19|20)(:isDigit::isDigit:)'.
(matcher matches: 'Aug 6, 1996')
ifTrue:��
[Array��
with: (matcher subexpression: 5)
with: (matcher subexpression: 2)
with: (matcher subexpression: 3)]
ifFalse: ['no match']
(should answer ` #('96' 'Aug' '6')').
you could make two subexpressions��
��'([\s.;\:!?]*)(#\w+)'
first subexpression is��([\s.;\:!?]*)��
and second subexpression is��(#\w+)��
and then use��
It understandards these
messages:
subexpressionCount
Answers the total number of subexpressions: the highest value that
can be used as a subexpression index with this matcher. This value
is available immediately after initialization and never changes.
subexpression: anIndex
An index must be a valid subexpression index, and this message
must be sent only after a successful match attempt. The method
answers a substring of the original string the corresponding
subexpression has matched to.