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 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: 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