Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9161127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:53:54+00:00 2026-06-17T13:53:54+00:00

In Google Apps Scripts, I’m trying to match a URL using RegExp using the

  • 0

In Google Apps Scripts, I’m trying to match a URL using RegExp using the following function.

function testRegex(){
  var str = "href='https://sites.google.com/a/domain.com/image-store/images/Image1.jpg?attredirects=0'";
  var regex = new RegExp('http[:a-zA-Z\.\/\-_]{0,100}Image1.jpg', 'gi');
  str = str.replace(regex,"new_url");
  Logger.log(str);
}

When I input the same regexp and string into the regular expression tester at http://www.regular-expressions.info/javascriptexample.html , it works. However, it doesn’t work in Google Apps Scripts.

Any ideas why?

EDIT:
I figured the problem is with the underscore. Replacing with \w helps. So, when I replace the Regex with

https[\.a-zA-Z0-9\/+:\w-]{0,100}Image1.jpg

IT WORKS.

But, it still doesn’t match an underscore. For example, it doesn’t work with the following the URL

https://sites.google.com/a/domain.com/image-store/_/rsrc/1351707816362/images/Image1.jpg
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:53:55+00:00Added an answer on June 17, 2026 at 1:53 pm

    I didn’t debug your code, but I tried it on repl.it and verified that it is not correct in Chrome’s V8 JavaScript either. I suspect there is a bug here that is unrelated to Apps Script.

    EDIT: This works:

    function testRegex(){
      var str = "href='https://sites.google.com/a/domain.com/image-store/_/rsrc/1351707816362/images/Image1.jpg'";
      var regex = new RegExp('https[\.a-zA-Z0-9\/+:\w_-]{0,100}Image1.jpg', 'gi');
      str = str.replace(regex,"new_url");
      Logger.log(str);
    }
    

    It didn’t match underscores because you didn’t specify an underscore in the character class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using the following code in Google Apps Script, the function runs properly, but
I'm using a general Google Apps Script function to be able to read, prettify
How can I delete a post from a Google Group using Google Apps Scripts?
I'm trying to work out if it is possible to use Google Apps Scripts
I have created a simple webapp using Google Apps Scripts. The UI simply displays
I'm trying to get the following Google Apps script to work, taken from another
Using google-apps-script from google-spreadsheet, I'm trying to fetch some hundreds of rows of data
In a Google Apps Script, I have the following script: function doGet() { return
Using Google Apps Script, I've made a UI for use on a Google Spreadsheet.
Using Google Apps Script. I know it is not a programming issue, but got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.