LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-23-2005, 12:08 AM   #1
eremit
LQ Newbie
 
Registered: Mar 2005
Location: Berlin
Distribution: xandros 2.04
Posts: 7

Rep: Reputation: 0
Regexp problem


Hi, sitting here reading for my exam and found this in last years exam:

A project has generated a numbered sequence of xml files. The filenames of interest consist of a 3 digit zero-padded number followed by ".xml" extension. Which regular expression will match all these numbered xml files, but NOT files that have letters before the .xml, have a sequence number with more than 3 digits, or have a ~ appended to the end?

a) "...\.xml$"
b) "[0-9]*3\.xml$"
c) "[0-9]\{3\}\.xml"
d) "[0-9]*\.xml$"

The problem is that I can't find any of the options to fit into the specification...

as I see it:
a) will match e.g. a99.xml
b) will not match every correct filename because of having the "hardcoded" number 3 in it
c) will match even if a ~ is appended
d) will match 000000222.xml

and on top of this; all the options will match if there is a leading letter etc. because the ^ is missing in the beginning of the regexp.

anyone out there that can find one that will match or is it not possible to answer correct on this question?

btw my lecturer isn't available, therefore I ask you guys

eremit
 
Old 06-23-2005, 12:31 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
what language?
 
Old 06-23-2005, 12:37 AM   #3
eremit
LQ Newbie
 
Registered: Mar 2005
Location: Berlin
Distribution: xandros 2.04
Posts: 7

Original Poster
Rep: Reputation: 0
actually it doesn't say, but I assume it is bash script because it is the only place we have used regexp in this unit.
 
Old 06-23-2005, 01:59 AM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
regexp in bash scripts? I didn't think bash even supported regexp's on its own. Do you mean in conjunction with a tool like sed or grep?
 
Old 06-23-2005, 02:00 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
The c) is near perfect for your regexp...

try :
Code:
ls /path/to/directory | egrep '^[0-9]{3}.xml$'

Last edited by keefaz; 06-23-2005 at 02:07 AM.
 
Old 06-23-2005, 02:40 AM   #6
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Code:
ls /path/to/directory | egrep '^[0-9]{3}.xml$'
You need a \ before .:
Code:
ls /path/to/directory | egrep '^[0-9]{3}\.xml$'
ta0kira
 
Old 06-23-2005, 06:48 AM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
true
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
regexp help cliff76 Linux - Newbie 3 03-07-2008 02:15 PM
little help for regexp EmOuBi Linux - Newbie 6 08-06-2005 02:19 AM
PHP regexp problem abdul_zu Linux - Software 2 04-03-2005 07:35 AM
regexp help ... pld Programming 1 03-15-2005 03:45 PM
perl regexp problem raven Programming 4 03-21-2004 11:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration