Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking string for predefined format
Message
From
15/08/2000 11:22:19
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00403485
Message ID:
00404984
Views:
17
>>>>>>
oRegExp=CREATEOBJ('vbscript.regexp')
>>>>>>oRegExp.Pattern = '\d{6}[A-Z]-[A-Z]\d{6}[A-Z]-[A-Z]\d{6}[A-Z]{2}-[A-Z]{2}\d{6}[A-Z]'
>>>>>>? oRegExp.Test('012345A-B012345C-D012345EF-GH012345I')
>>>>>>? oRegExp.Test('012345A-b012345C-D012345EF-GH012345I')
>>>>>
>>>>>Great, Ed. Thanks a lot. One little problem: [A-Z] could be also space, e.g.
>>>>>in mask: lcMask = "999999X-X999999X-X999999XX-XX999999X"
>>>>>X could be upper alpha or space.
>>>>
>>>>Like this is difficult? Change [A-Z] to [A-Z ]
>>>>
>>>>This is definitely a case of RTFM; you neeed to read the docs to see what all the capabilities are.
>>>
>>>Yes, I'm reading :)
>>>
>>>lcAPN = "000000 - 001000 - 000000 - 000000"
>>>oRegExp=CREATEOBJ('vbscript.regexp')
>>>oRegExp.Pattern = '\d{6}[A-Z ]-[A-Z ]\d{6}[A-Z ]-[A-Z ]\d{6}[A-Z ]{2}-[A-Z ]{2}\d{6}[A-Z ]'
>>>? oRegExp.Test(lcApn) && .F. - should be .T.
>>
>>No it shouldn't - the trailing character that would match [A-Z ] in the last position is not present - you trimmed or excluded it. This is definitely a case of RTFM.
>
>Ok, this seems to be the syntax for my lcMask: (though I may be wrong)
>
>oRegExp.Pattern = '\d{6}[A-Z ]-[A-Z ]\d{6}[A-Z ]-[A-Z ]\d{6}[A-Z ]{2}-[A-Z ]{2}\d{6}[A-Z ]{0,1}'
>
It's wrong, or at least, not optimal:

oRegExp.Pattern = '^\d{6}[A-Z ]-[A-Z ]\d{6}[A-Z ]-[A-Z ]\d{6}[A-Z ]{2}-[A-Z ]{2}\d{6}[A-Z ]?$'

The leading '^' and '$' are important to ensure that the test matches the exact string as tested; otherwise, preceding or trailing characters would be allowed.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform