The Support Group Blog

GAM-RegEx_800x330

Search and Replace Regular Expressions in Google App Maker

Although Google App Maker is a great example of a “low-code” development platform, it isn’t exactly a “no-code” platform. To really leverage the potential power of Google App Maker, you need to roll up your sleeves and write some code. Luckily the code of choice for Google App Maker is JavaScript, one of the most widely used and well-documented languages out there. JavaScript is the language that web browsers use to execute most website workflows, so it only makes sense that Google App Maker would use it too. Even though JavaScript is one of the more approachable languages available, it's still a deep and varied subject that will require a book to explore completely. Having said that, there are some aspects of JavaScript that you will most likely find useful in Google App Maker, specifically when it's combined with another tool called regular expressions (regex).

Unlike most websites that are often mechanisms to distribute data, a Google App Maker app is usually a receiver and parser of data. Take a common app like a CRM, it can receive new contacts and sales leads while compiling old and new data into dashboard displays and reports. Natively, Google App Maker does a pretty good job of giving you the tools necessary to work with the tables, records and fields that are hosted on your Google Cloud SQL instance. However, when it comes to searching, replacing and changing the data inside of a coded workflow or function, you need to rely on regex.


The Matching Game

Regex allows us to easily work with the data arrays and blocks of text we often find in JavaScript code. Using regex you can search your text for a character or pattern of characters and even replace text as we can do in a word processor. Once you learn a few simple commands, you will be well on your way to mastering text in Google Maker App JavaScript code.

Let's say you want to replace a certain name in a list. Your list looks like this:

Tom
Bill
Sally
Raul
Bill

Now you want to swap out the first "Bill" for "Issac." Using the regular expression literal construction your code would be:
RegEx_screenshot1

 The result would be:

Tom
Issac
Sally
Raul
Bill

If you want to replace every instance of Bill, you would specify “g” after “Bill” in order to execute a global search as so:

RegEx_screenshot2

The result would be:

Tom
Issac
Sally
Raul
Issac

Regex expressions are case-sensitive unless otherwise specified. If the last "Bill" was actually spelled "bill," you could use the “i” flag to make regex less discriminant and yield the same result above.

RegEx_screenshot3

If you don't include the “i" flag, the result would be:

Tom
Issac
Sally
Raul
bill

You can use regex to search and replace more than just words, but any pattern or combination of characters. Take this example:

RegEx_screenshot4

It would give you:

Tom
IssXc
SXlly
RXul
IssXc

We're just scratching the surface of what you can do with regex in JavaScript. Explore the many options regular expressions offer for searching and replacing data within your scripts: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions 

Keep me posted

Share this entry
0 replies
BrowseMode

Sign up to receive news and information about the FileMaker platform and other custom app development tools.

Keep me posted

Most Popular

Developer Resources

News, Tips & Tricks and Demos