Training, Open Source computer languages

This is page http://www.wellho.net/forum/News-cha ... -more/Regular-Expressions-beginner.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
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))
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.

© 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