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
 
20.9.2014 - We have just updated our course layouts and descriptions and added our 2015 schedule.

Regular Expressions (beginner)

Posted by Jonno (Jonno), 7 March 2004
Hi All,

Sorry if I'm in the wrong place but I have a question about regular expressions. I'm new to this and am finding them a bit puzzling.

My question is....Some sequences of inputs produce the same sequences as outputs. eg input sequence <0,0,0> produces output sequence <0,0,0>.

What would be the regular expression that describes all such sequences. Is it 0* or 0+ (plus is superscript) ie. is it one or more 0's or zero or more 0's.

Thanks in advance.

Jonno


Posted by admin (Graham Ellis), 8 March 2004
I rather suspect that you're looking for something like
       <(0,)*0>
which means
* A less that sign
* 0 followe by a comma 0 or more times
* a 0
* a greater than sign

Although a regular expression is a "fuzzy match", you have to be exact in how you descibe that match - you have to know exactly what combinations are allowed and which aren't.  I have made the following assumptions in my answer
* That you're looking for the string embedded anywhere in a piece of text
* That the < and > sign must be present
* That you must have at least one zero present
* That there's no maximum to the number of zeros
* That the , is always present as a separator
* That a trailing , is not allowed
* That white spaces are not allowed anywhere in the sequence.

If any of these assumptions is incorrect, the regular expression will need changing - and there must be hundreds of combinantions of answers to the things I assumed - not only things like "yes" and "no", but "no - white spaces are allowed but only after the comma".  This world of detailed study of what look like simple strings is typical of the regular expression world.

There's a further complexity.  Rgeular expressions differ slightly from one language to another; the common sequences work more or less across the board these days, but the extensions can be different.   Am I allowed a "+" for 1 or more characters?  Is white space a \s, a [ \r\t\n] or a [[:space:]] or a \p{space}, or are several of these allowed?   And so on ...

I hope this answer helps - please do follow up if you want me to tune my answer to meet a different scenario to the one I have assumed (after all - an assumption makes an "ass out of u and me".  If you can tell me what language you would like me to use in my answer, that would be a great help too.

Graham

Posted by Jonno (Jonno), 10 March 2004
Thanks for that Graham. The less than and more than symbols are meant to denote the fact that this is an input sequence of a series of zero's. Thats why I thought 0+ (plus sign in superscript). This denotes (I think) a sequence of one or more zero's

Thanks for your help. Its a minefield innit  

Regards Jonno



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., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho