Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
TCL regexp

Posted by Arshad (Arshad), 27 November 2007

regexp [0-9]* hello

returns SUCCESS, which I thought will match only digits and not Alpha.

Am I missing on something?

Posted by Arshad (Arshad), 27 November 2007
Actually I have grammer in ABNF format for a Digit-pattern-

Digit-pattern = 1*( characterPosition [RepeatCount ] )
Digit-pattern = 1*( characterPosition [RepeatCount ] )
characterPosition = character / characterSet / characterInvSet
characterSet = "[" 1*digitSetList "]"
characterInvSet = "[" "^" 1*digitSetList "]"
digitSetList = DIGIT [ "-" DIGIT ]
character = DIGIT / "*" / "#" / "x" / "X"
RepeatCount = "{" RepeatRange "}"
RepeatRange = Count / ( Count "," Count )
Count = 1*DIGIT


which I want to convert to a regexp Pattern, I worked out onto this...


Digit-Pattern      (([0-9*#xX]*)|(\[[0-9]*[-0-9]*\])|(\[\^[0-9]*[-0-9]*\]))*({[0-9]+[,]?[0-9]*})
characterPosition   ([0-9*#xX]*)|(\[[0-9]*[-0-9]*\])|(\[\^[0-9]*[-0-9]*\])
CharacterSet      \[[0-9]*[-0-9]*\]
CharacterInvList    \[\^[0-9]*[-0-9]*\]
digitSeList      [0-9]*[-0-9]*
character      [0-9*#xX]+
RepeatCount      {[0-9]+[,]?[0-9]*}
RepeatRange      [0-9]+[,]?[0-9]*
Count            [0-9]*      


The problem is that even the alphabets are matching "characterPosition" which should not happen.

so 123{3} must atch the Digit-Pattern but abc{3} must not.

Posted by Arshad (Arshad), 27 November 2007

Need urgent help...if someone can help me out with this one...

Posted by admin (Graham Ellis), 28 November 2007
on 11/27/07 at 15:21:47, Arshad wrote:
regexp [0-9]* hello

returns SUCCESS, which I thought will match only digits and not Alpha.

Am I missing on something?


You are asking if the string hello contains zero or more digits, which it does.   In fact any string at all contains zero or more digits ... so will match your regular expression.

Posted by admin (Graham Ellis), 28 November 2007
on 11/27/07 at 17:09:39, Arshad wrote:
Need urgent help...if someone can help me out with this one...



You'll find that our "terms of reference" for this forum say that we'll look to provide guidance within 24 hours. If your requirement is so urgent that you need to start nagging for a quick answer within just 2 hours, you'll be far better placed taking a commercial support service on board.


Posted by Arshad (Arshad), 28 November 2007
But I thought it will match numbers from 0-9 only and not alphabets from a-z and A-Z, which it does.

Posted by admin (Graham Ellis), 28 November 2007
on 11/28/07 at 08:27:31, Arshad wrote:
But I thought it will match numbers from 0-9 only and not alphabets from a-z and A-Z, which it does.


regexp [0-9]* hello

looks for a string of zero or more digits within the word "hello".  As there are zero digits between each of the pairs of characters - it matches many times over ...

h - e - l - l - no digits - o

You may want anchors on your regular expression.  The bestway to learn these regular expressions is here.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho