regex

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

regex

CdAB63
Btw, in my last e-mail I meant something simpler than:

| mx0 mx1 str oc |
Transcrit clear.
mx0 := RxMatcher forString:
'(\d+)\s(\d\d)/(\d\d)/(\d\d\d\d)\s((\d+\s)+)(\d+)'.
mx1 := RxMatcher forString: '(\d+)\s'.
str := '1 27/05/1963 10 22 31 01 06 04 19 10 111'.
(mx0 matches: str)
ifFalse: [ Transcript show: 'mx0 failed to match: ',str; cr ]
ifTrue: [
    Transcript show: 'Identified ',mx0 subexpressionCount asString,'
subexpressions.'; cr.
    Transcript show: 'Id: ',(mx0 subexpression: 2); cr.
    Transcript show: 'Date: ',(mx0 subexpression: 3),'/',(mx0
subexpression: 4),'/',(mx0 subexpression: 5); cr.
    Transcript show: 'Numbers: ',(mx0 subexpression: 6); cr.
    Transcript show: 'Acct: ',(mx0 subexpression: 8); cr.
    oc := mx1 matchesIn: (mx0 subexpression: 6).
    oc isNil
    ifTrue: [
        Transcript show: 'mx1 failed to match: ',(mx0 subexpression: 6);
cr ]
    ifFalse: [
        1 to: oc size do: [ :i |
            Transcript show: 'Nb(',i asString,') = ',(oc at: i); cr ]]].

Which is just too much text for little action...




signature.asc (269 bytes) Download Attachment