Re: [Dorset] Slight OT: Regular Expressions in Winblows
Hi Terry, Simple I thought; the expression I want is '_[0-9]{4}'. However, the only thing I could get to work, using Notepad++ and MS Visual Studio Find tools, was '_[0-9][0-9][0-9][0-9]'. Here at home I can get my original expression t o work in Kate, but not in Notepad++ running under wine. So! I thought; this i s a Windows thing. But I can't get it to work in nano either, although '[0-9] {4}' finds any 4 digits, but '_[0-9]{4}' won't find four digits with a preceding underscore. What's the obvious thing I'm missing? History. Regular expressions were introduced to text processing by Ken Thompson who we recently mentioned. The syntax has evolved a bit by then and there are variations today. Your regexp could be written as _[0-9][0-9][0-9][0-9] _[0-9]\{4\} _[0-9]{4} and possibly others once you introduced non-Unix into the mix. And in those, the character class [0-9] could be replaced by \d, for digit, in some variations. The first of the six is the oldest; a Basic Regular Expression as POSIX calls it. That would work in most places. How do you know which to use where? Depends on the program being used. Cheers, Ralph. -- Next meeting: Blandford Forum, Wednesday 2011-03-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] Slight OT: Regular Expressions in Winblows
On Monday 21 Feb 2011, Ralph Corderoy wrote: No. Could it be that /[0-9]{4}/ worked because you were telling nano you were searching for a regexp with M-R, but when you tried /_[0-9]{4}/ you forgot to do that? The prompt for the search string says whether it's expecting a regexp or not. Actually, this is weirder than I thought. Originally, I proved the regexp in Kate andf then copied it from the Kate Find field to the nano Find field. No matter what I did, I couldn't get a match. Just now, I put in the regexp that always worked \[0-9]{4}\ into nano and then copied the underscore char from the nano edit window and pasted it into the Find field. It worked! Then I deleted the underscore char and typed it instead. It worked! I then copied and pasted the regexp from Kate agian. You guessed it. It worked! I can't understand it, but I guess I'll never find out what I was doing wrong now. Having tried here, I find /_[0-9]{4}/ works fine in nano, only finding what I expected. (The // are merely quotes for regexps, not to be entered.) It does for me now ;-) -- Terry Coles 64 bit computing with Kubuntu Linux -- Next meeting: Blandford Forum, Wednesday 2011-03-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] Slight OT: Regular Expressions in Winblows
On 21 February 2011 21:38, Keith Edmunds k...@midnighthax.com wrote: On Mon, 21 Feb 2011 21:21:14 +, l...@discoverlinux.co.uk said: In vi :1,$s/_[0-9][0-9][0-9][0-9]/found/g In case it isn't clear, Vim is available on Windows as well. I know Vim isn't everyone's cup of tea (for some inexplicable reason), but good to know that there is a powerful editor available for those unfortunate enough to need to edit files on a Windows platform. also, you can save a couple more keystrokes if you want to operate on all lines in the buffer: :%s/find/replace/g -- regards, jr. time flies like an arrow, fruit flies like a banana. -- Next meeting: Blandford Forum, Wednesday 2011-03-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue
Re: [Dorset] Slight OT: Regular Expressions in Winblows
On Monday, February 21, 2011 09:38:24 pm Keith Edmunds wrote: On Mon, 21 Feb 2011 21:21:14 +, l...@discoverlinux.co.uk said: In vi :1,$s/_[0-9][0-9][0-9][0-9]/found/g In case it isn't clear, Vim is available on Windows as well. I know Vim isn't everyone's cup of tea (for some inexplicable reason), but good to know that there is a powerful editor available for those unfortunate enough to need to edit files on a Windows platform. -- Next meeting: Blandford Forum, Wednesday 2011-03-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue And of course winviis available on windows too. Andy -- Next meeting: Blandford Forum, Wednesday 2011-03-02 20:00 Meets, Mailing list, IRC, LinkedIn, ... http://dorset.lug.org.uk/ How to Report Bugs Effectively: http://goo.gl/4Xue