Filename.replace(/^.*[\\\/]/, '') -: explain the expression
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 05:36 AM
Hi can anyone make me understand the below expression.
FileName.replace(/^.*[\/]/, ‘’)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2022 05:46 AM
Hey @Pakhi,
This expression will replace the element that is matched by the regex (/^.*[/]/), with an empty string ''
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 06:35 AM
Hey can you explain this regex please if you know
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 06:42 AM
Sure.
. - matches any character except a line break
* - means 0 or more of the preceding token
[ ] - means a character set
\/ - is practically an escaped forward slash character - /
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 10:15 AM
Basically, the expression removes anything from the beginning of the string to the last forward slash or backslash. In other words, get only the filename from the input string.
See some examples in the screenshot below. The highlighted parts are matched with ^.*[\\\/]
and will be removed.