Question: Can someone tell me whats the definition of the two code below ?

```
$file_directory =~ s/[^\\\/]+$//;

$new_id =~ m/([ABCISRDT]\d\d\.\d\d\.\d\d)$/i)

```

It is similar to the code below but the syntax is different

```
$string_to_change =~ s/pattern_to_look_for/string_to_replace_with/g;

```

I understand s/[ is search,^ beginning of line" symbol and $ is end of line" symbol; I don't understand is \/]+.

Let say that the file directory is W:\folder\_1\music\common in Perl script it should be W:\\folder\_1\\music\\common but there is an extra one \ in it and (I realize when I was typing it requires 3 \ in order to display 2 \)what does the + stands for ?If I wish to convert it into Linux should the changes be like this ?

```
$file_directory =~ s/[^\\//]+$//;

```

As for the last code I need someone to explain to me what it does Thank you .

Answer: 
This expression

> 
> $file\_directory =~ s/[^\\\/]+$//;
> 
> 
> 

will match with all the characters after the last forward or backward slash, and replace it with nothing. Usually this will end up with the directory name. (Note that there are safer ways to do this, which are also cross-platform. For instance [Path::Class](https://metacpan.org/pod/Path::Class).)

* `[^]` is a negated character class, and will match anything not in the group.
* `+` gives one or more matches
* `$` matches end of string

> 
> If I wish to convert it into Linux should the changes be like this ?
> 
> 
> 

Since the line already checks for both slashes, the code in question should work for Linux as is.
Those square brackets delimit a *character class*, which means any of the chars listed. A character class the starts with `^` is a *negated* character class - it means anything *other* than those chars listed.

The expression:

```
[^\\\/]+$

```

Means "one or more of any char other than either slash at the end of input"