1754419 Members
2713 Online
108813 Solutions
New Discussion юеВ

Help on RegExp nedded

 
SOLVED
Go to solution
Kalin Evtimov
Regular Advisor

Help on RegExp nedded

Hi!
I am stuck..
I need a regexp, which finds a file named 'something.log'
My regexp finds also something.log.1 and something.log.2 and so on..argh...

It says:
if ($file =~ /something.*.log/)....

How should I change it?

Thank you!

7 REPLIES 7
Arunvijai_4
Honored Contributor

Re: Help on RegExp nedded

Hello,

You can give exact name in "" (double quotes)

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Senthil Kumar .A_1
Honored Contributor
Solution

Re: Help on RegExp nedded

Hi Kalin,


Can you try,

if ($file =~ /something.*.log$/)....

Notice there is "$" after log character.

Regards,
Senthil Kumar .A
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
Peter Godron
Honored Contributor

Re: Help on RegExp nedded

Kalin,
have you tried:
if ($file =~ /something*.log/)....

(removed first full stop)
Kalin Evtimov
Regular Advisor

Re: Help on RegExp nedded

Senthil Kumar .A ├В┬┤s version worked, I just added brackets:

$file =~ /something.*[log]$/

but it should work also without brackets.

Thank you!
dirk dierickx
Honored Contributor

Re: Help on RegExp nedded

the brackets are groups of chars to match to. now your regex will also match all files ending with the letters l, o or g. ex: ogl, gol, glo, gl, ol, lo, go, o, ...
not what you want i guess. it hasn't happened to you yet, because you don't have any other files with an extension made out of the letters l, o or g. but you can never be sure (.o files are common)
Kalin Evtimov
Regular Advisor

Re: Help on RegExp nedded

Very kind of you, thank you, I`ll fix it.
Senthil Prabu.S_1
Trusted Contributor

Re: Help on RegExp nedded

Hi,
Try this one

($testfile =~ /something.*.log$/)


HTH,
Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.