Monday 14 January 2019

Split filename with 'brackets' and 'comma' by a regex

The following Google Apps Script code was developed as a means to extract specific parts of a Google drive folder name (shown in the next blog post) by using a regular expression (regex). It is possible to achieve the same effect by using 'split' more than once to query the folder name but I wanted to achieve it all within a single line.

Regex breakdown - /[( ),]+/  - https://regex101.com/
  • //  start/end of regex.
  • [ ]  match any character in the set.
  • ( ),  match curly brackets and comma.
  • +  match between 1 and any number of items.
An example folder name has been used in the code below to show you this concept.

Split name containing (), by regex.gs

No comments:

Post a Comment