Regular expression help

i want to get file name form this strings:

  • “/home/theuser/myfile_کلمه.zip”
  • “C:\myfile_کلمه.zip”
  • “myfile_کلمه.zip”

i need get with match from strings ‘myfile_کلمه.zip’?
what is correct pattern ?

i use .match(/^.*([^\/\\]+)$/i); but did not work.

You can use this if you know the files are all .zip:

var res = str.match(/([^\\/\\\\]+)\\.zip$/)

no … it’s not work with all file extention … ‘myfile_کلمه.zip’ is an example file … i dont know what’s my file name and extention i just need file with extention … and work with windows, unix and solo mode !!!

OK, in that case:

var res = /([^\\/\\\\]+)\\.[a-z]+$/ig.exec(str);
var res = /([^\\/\\\\]+)\\.[a-z0-9]+$/ig.exec('c:\\windows\\folder\\file_صثص.dwe6');
alert(res[1]); // c:windowsolderile_صثص

wrong math !!!

Then add a full colon in to the character group.

what is your mean ?

get me an example !!!

Even better, here is a tutorial on character classes

A full colon is the : character, the two dots that are one above the other.

You will want to add the full colon to the character class. That is the group of characters that are contained within the square brackets. The square brackets are the left square bracket [, and the right square bracket ].

In order to do that, I suggest that you position your editors insertion bar just inside one of the square brackets, hold down the shift key on your keyboard, and while the shift key is held down, to depress also the key with a semicolon below (which is a period on top of a comma) and the full colon (previously explained) above. Do not depress the key for more than half of a second, otherwise there will be a repetition of the key. Once you have released the key you may also release the shift key, and you will have then placed the correct character in the correct location to achieve your objective.

Please let us know if you require any further assistance.

:rofl: great helpppp!!!

so what’s my correct regex ? :confused:

This is untested, but I would say that your correct regex involves changing

so that it has a full colon added to it, such as this: