Monday, 31 December 2018

Extract ID from Url by a regex

The following Google Apps Script code is another take on this post for splitting a Google file Url to get the ID part - but this time using a regular expression (regex). An example Url has been included but in my projects I am usually getting this from a cell that has been linked using this value.

Regex breakdown - [-\w]{25,} - https://regex101.com/
  • [ ]  match any character in the set.
  • -  matches a "-" character.
  • \w  matches any word character (alphanumeric & underscore).
  • {25,}  match 25 or more of the preceding token

Credit to the following Stack Overflow post where I initially found this.

No comments:

Post a Comment