I'm not sure what are you trying to get. But I guess you want to get the word of test
from your first sentence. So use this pattern:
~\\\\(\w+)\.pdf$~
And then $1
containing what you need.
-
~
delimiter
-
\\\\
matches two backslashes literally
-
(
capturing group $1
(which is containing what you need to get)
-
\w+
matches one or more letter, number or underscore
-
\.
matches a dot literally
-
$
end of string
Here is your pattern in the question ~\\\(.+)\.pdf~
. The problem of your pattern is .+
. Because it means one or more character(s) (every character even \
). So your pattern matches that two backslashes which are in the beginning of your string, and the rest of backslashes will be match as every character (.+
).
To avoid this, you have to use \w
which means any letter, number or underscore instead. In this case the matched part will be just test
.