Replacing specific character

I seem to be stuck trying to replace the last comma with “&” using replace. Is this possible?

Example 1: name1, name2, name 3
Example 2: name 1, name 2

The outcome I’m after is

Example 1: name1, name2 & name3
Example 2: name1 & name2

Thank you!

Hi @inthemaking
You can apply following method to achieve this:
{{replace(join(add(remove(split(167.text; “,”); last(split(167.text; “,”))); “and” + space + last(split(167.text; “,”))); “,”); “,and”; space + “and”)}}

Text: name 1,name 2, name 3

And the output is:
image

Regards,
Msquare Automation - Gold Partner of Make

Free Consultation | Live Implementation

Visit us here | Youtube Channel

Welcome to the Make community!

Yes, you can do this with the replace function only.

e.g.:

{{replace(49.example; "/, ([^,]+)$/"; " & $1")}}

Screenshot_2024-07-03_130744

Example:
Screenshot_2024-07-03_130732

Output:
Screenshot_2024-07-03_130750

For more information, see the “replace” function documentation in the Help Center.

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too —

General

Help Center Basics

Articles & Videos

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

1 Like

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

View Module Export Code

JSON

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 1,
                    "module": "util:ComposeTransformer",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "value": "{{replace(49.example; \"/, ([^,]+)$/\"; \" & $1\")}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 247,
                            "y": -830
                        }
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

3 Likes

Ahh I was about 3/4 of the way there, missed the last part. Thank you!

1 Like

No problem, glad I could help!

1. If anyone has a new question in the future, please start a new thread. This makes it easier for others with the same problem to search for the answers to specific questions, and you are more likely to receive help since newer questions are monitored closely.

2. The Make Community guidelines encourages users to try to mark helpful replies as solutions to help keep the Community organized.

This marks the topic as solved, so that:

  • others can save time when catching up with the latest activity here, and
  • allows others to quickly jump to the solution if they come across the same problem

To do this, simply click the checkbox at the bottom of the post that answers your question:
Screenshot_2023-10-04_161049

3. Don’t forget to like and bookmark this topic so you can get back to it easily in future!

4. Do join the unofficial Make Discord server for live chat and video assistance

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!