LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 01: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, 01:31 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,441

Rep: Reputation: 103Reputation: 103
what language?
 
Old 06-23-2005, 01: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, 02: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, 03:00 AM   #5
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 136Reputation: 136
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 03:07 AM.
 
Old 06-23-2005, 03: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, 07:48 AM   #7
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 136Reputation: 136
true
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:15 PM
little help for regexp EmOuBi Linux - Newbie 6 08-06-2005 03:19 AM
PHP regexp problem abdul_zu Linux - Software 2 04-03-2005 08:35 AM
regexp help ... pld Programming 1 03-15-2005 04:45 PM
perl regexp problem raven Programming 4 03-22-2004 12:49 AM


All times are GMT -5. The time now is 09:52 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration