0

I am trying to come up with a regex that will match the following.

file://server-name-01/e$/(any file or subfolder)?ds=test_01

Below is the expression i've been working with but for some reason this will match any server name.

.*[a-zA-Z]:\/\/.*[sf.ps.gdo02].*\?ds=[a-zA-Z0-9_]+$

My goal is to match a specific server name and admin share so that any file or subfolder targeted within the share would be a match.

I'm also interested in the ability to match the following using 1 expression.

1) file://server-name-01/e$/(any file or subfolder)?ds=test_01
2) file://server-name-02/e$/(any file or subfolder)?ds=test_01
3) file://server-name-03/e$/(any file or subfolder)?ds=test_01 

Forgive me as i'm fairly new to defining expressions but any help would be greatly appreciated.

  • a link for groups: http://www.regular-expressions.info/brackets.html a link for classes: http://www.regular-expressions.info/charclass.html – Casimir et Hippolyte Jun 19 '14 at 17:49
  • Thanks for your quick responses. I was able to achieve what i was looking for by using the following expression. 'code' ^.*\/\/server.name.\d\d\/.*[Ee]\$\/.*\?ds=.*$ – user3757483 Jun 19 '14 at 20:51

2 Answers2

0

Regex:

^.*\/([^\/]+)\/([^\/]+)\/([^\/]+)\?ds=.*$

Live demo

Example:

file://server-name-01/e$/(any file or subfolder)?ds=test_01

Match:

1    `server-name-01`
2    `e$`
3    `(any file or subfolder)`
CMPS
  • 7,733
  • 4
  • 28
  • 53
0

The following works in Perl. Not sure if you need more flexibility, but if I understood your requirements correctly, this works (coded it, tested it, pasted in directly).

printf("Enter your expression: ");
my $exp = <STDIN>;
chomp($exp);

if ($exp =~ /file:\/\/server-name-0[1-3]\/e\$\/.*\?ds=test_01/)
{
    printf("Matched.\n");
}
else
{
    printf("NO MATCH!\n");
}
John
  • 342
  • 3
  • 10