# String.replaceAll not working in Groovy script

**URL:** <https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71>\
**Category:** ReadyAPI\
**Tags:** readyapi, api, migrated, scripting\
**Created:** [February 4, 2024, 6:08am UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71 "2024-02-04T06:08:25Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 4, 2024, 6:08am UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/1 "2024-02-04T06:08:25Z")

</div>

> Originally posted by **Alejandro59** on February 03, 2024

I am using a file as a template in order to create new files. The template file contains “placeholders” in the form of **[plc]placeholderName[plc]**. I want to replace the placeholder at runtime with values as shown in the groovy script.

However the String.replaceAll() method seems not to work (placeholders don’t get replaced)

Am I missing something?

The contents of the Template.xml are:

 ![](https://canada1.discourse-cdn.com/flex049/uploads/smartbear_prod/original/1X/2547c9b9b1e5604bd01eefd5922d410671baa6e6.png)

My groovy script is:

 ![](https://canada1.discourse-cdn.com/flex049/uploads/smartbear_prod/original/1X/751bbff4c1dbeda9d146c92a79b5ae266ccdcc52.png)

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 10:08am UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/2 "2024-02-05T10:08:38Z")

</div>

> Originally posted by **ChrisAdams** on February 05, 2024

Hi,

I do something similar, but I tend to ‘pull’ the edited version into the step that makes the request rather than your approach to ‘push’.

Your script seems sound or is at least until line 15. I guess the log statement shows the replace all has worked.

My suggestion…

- comment out lines 16 onwards.
- After line 15, create a new line 16 containing… return templ; or might be return (templ);
- In the step that actually makes the API request go to the payload panel and empty it.
- Then, in the same panel, do a mouse right-click and a context menu pops up.
- Select ‘get data’ and pick the script result option for the Groovy step that does the replace.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 10:32am UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/3 "2024-02-05T10:32:45Z")

</div>

> Originally posted by **Alejandro59** on February 05, 2024

Hi Chris,

Thanks for your response.

Did as suggested but the result is the same. The script returns the “template” with the placeholders NOT replaced.

Regards

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 11:29am UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/4 "2024-02-05T11:29:54Z")

</div>

> Originally posted by **ChrisAdams** on February 05, 2024

OK, going back a step, does the log.info on line 15 actually show the expected content or is still the unreplaced version?

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 11:34am UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/5 "2024-02-05T11:34:22Z")

</div>

> Originally posted by **Alejandro59** on February 05, 2024

It displays the unreplaced version.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 11:59am UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/6 "2024-02-05T11:59:06Z")

</div>

> Originally posted by **ChrisAdams** on February 05, 2024

Can you paste in the updated script?

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 12:12pm UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/7 "2024-02-05T12:12:16Z")

</div>

> Originally posted by **ChrisAdams** on February 05, 2024

Got it. You need to re-assign the variable after a replace all.

E.g.

templ = templ.replaceAll(…

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 5:00pm UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/8 "2024-02-05T17:00:06Z")

</div>

> Originally posted by **Alejandro59** on February 05, 2024

Hi Chris,

Still does not work ☹

Here is the last version of the script

```auto
String templ = new File('C:/Templates/Template.xml').getText('UTF-8')

String AP_Initiator = "POP000106"
String originalSender = "9928:12341234A"
String finalRecipient = "9928:12341234B"

log.info("AP_Initiator: [$AP_Initiator]")
log.info("originalSender: [$originalSender]")
log.info("finalRecipient: [$finalRecipient]")

templ = templ.replaceAll("[plc]AP_Initiator[plc]", AP_Initiator)
templ = templ.replaceAll("[plc]originalSender[plc]", originalSender)
templ = templ.replaceAll("[plc]finalRecipient[plc]", finalRecipient)

log.info("ExpandedFileContents: $templ")
return (templ);

```

and the template file

```auto
<SPAN class="token prolog"><?xml version="1.0" encoding="UTF-8" standalone="no"?></SPAN>
<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>StandardBusinessDocument</SPAN> <SPAN class="token attr-name">xmlns</SPAN><SPAN class="token attr-value"><SPAN class="token punctuation attr-equals">=</SPAN><SPAN class="token punctuation">"</SPAN>http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader<SPAN class="token punctuation">"</SPAN></SPAN><SPAN class="token punctuation">></SPAN></SPAN>
	<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>StandardBusinessDocumentHeader</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
		<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>HeaderVersion</SPAN><SPAN class="token punctuation">></SPAN></SPAN>1.0<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>HeaderVersion</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
		<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Sender</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Identifier</SPAN> <SPAN class="token attr-name">Authority</SPAN><SPAN class="token attr-value"><SPAN class="token punctuation attr-equals">=</SPAN><SPAN class="token punctuation">"</SPAN>iso6523-actorid-upis<SPAN class="token punctuation">"</SPAN></SPAN><SPAN class="token punctuation">></SPAN></SPAN>[plc]originalSender[plc]<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Identifier</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
		<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Sender</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
		<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Receiver</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Identifier</SPAN> <SPAN class="token attr-name">Authority</SPAN><SPAN class="token attr-value"><SPAN class="token punctuation attr-equals">=</SPAN><SPAN class="token punctuation">"</SPAN>iso6523-actorid-upis<SPAN class="token punctuation">"</SPAN></SPAN><SPAN class="token punctuation">></SPAN></SPAN>[plc]finalRecipient[plc]<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Identifier</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
		<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Receiver</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
		<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>DocumentIdentification</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Standard</SPAN><SPAN class="token punctuation">></SPAN></SPAN>urn:oasis:names:specification:ubl:schema:xsd:Invoice-2<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Standard</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>TypeVersion</SPAN><SPAN class="token punctuation">></SPAN></SPAN>2.1<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>TypeVersion</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>InstanceIdentifier</SPAN><SPAN class="token punctuation">></SPAN></SPAN>[plc]AP_Initiator[plc]-[plc]TimeStampNormalized[plc]<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>InstanceIdentifier</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Type</SPAN><SPAN class="token punctuation">></SPAN></SPAN>Invoice<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Type</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>CreationDateAndTime</SPAN><SPAN class="token punctuation">></SPAN></SPAN>[plc]TimeStampUTC[plc]<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>CreationDateAndTime</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
		<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>DocumentIdentification</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
		<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>BusinessScope</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Scope</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
				<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Type</SPAN><SPAN class="token punctuation">></SPAN></SPAN>DOCUMENTID<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Type</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
				<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>InstanceIdentifier</SPAN><SPAN class="token punctuation">></SPAN></SPAN>urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>InstanceIdentifier</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Scope</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Scope</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
				<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Type</SPAN><SPAN class="token punctuation">></SPAN></SPAN>PROCESSID<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Type</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
				<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>InstanceIdentifier</SPAN><SPAN class="token punctuation">></SPAN></SPAN>urn:www.cenbii.eu:profile:bii05:ver2.0<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>InstanceIdentifier</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Scope</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Scope</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
				<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>Type</SPAN><SPAN class="token punctuation">></SPAN></SPAN>COUNTRY_C1<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Type</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
				<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"><</SPAN>InstanceIdentifier</SPAN><SPAN class="token punctuation">></SPAN></SPAN>CY<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>InstanceIdentifier</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
			<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>Scope</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
		<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>BusinessScope</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
	<SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>StandardBusinessDocumentHeader</SPAN><SPAN class="token punctuation">></SPAN></SPAN>
 <SPAN class="token tag"><SPAN class="token tag"><SPAN class="token punctuation"></</SPAN>StandardBusinessDocument</SPAN><SPAN class="token punctuation">></SPAN></SPAN>

```

Since time is running out I am implementing a workaround outside ReadyAPI.

Anyway, many thanks for your prompt support; appreciated!

Best Regards

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 5:02pm UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/9 "2024-02-05T17:02:00Z")

</div>

> Originally posted by **Alejandro59** on February 05, 2024

The template in a better form:

```auto
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<StandardBusinessDocument xmlns="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">
	<StandardBusinessDocumentHeader>
		<HeaderVersion>1.0</HeaderVersion>
		<Sender>
			<Identifier Authority="iso6523-actorid-upis">[plc]originalSender[plc]</Identifier>
		</Sender>
		<Receiver>
			<Identifier Authority="iso6523-actorid-upis">[plc]finalRecipient[plc]</Identifier>
		</Receiver>
		<DocumentIdentification>
			<Standard>urn:oasis:names:specification:ubl:schema:xsd:Invoice-2</Standard>
			<TypeVersion>2.1</TypeVersion>
			<InstanceIdentifier>[plc]AP_Initiator[plc]-[plc]TimeStampNormalized[plc]</InstanceIdentifier>
			<Type>Invoice</Type>
			<CreationDateAndTime>[plc]TimeStampUTC[plc]</CreationDateAndTime>
		</DocumentIdentification>
		<BusinessScope>
			<Scope>
				<Type>DOCUMENTID</Type>
				<InstanceIdentifier>urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1</InstanceIdentifier>
			</Scope>
			<Scope>
				<Type>PROCESSID</Type>
				<InstanceIdentifier>urn:www.cenbii.eu:profile:bii05:ver2.0</InstanceIdentifier>
			</Scope>
			<Scope>
				<Type>COUNTRY_C1</Type>
				<InstanceIdentifier>CY</InstanceIdentifier>
			</Scope>
		</BusinessScope>
	</StandardBusinessDocumentHeader>
 </StandardBusinessDocument>

```

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 5:08pm UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/10 "2024-02-05T17:08:48Z")

</div>

> Originally posted by **ChrisAdams** on February 05, 2024

Sorry I couldn’t help you get over the line on this one.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 5:55pm UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/11 "2024-02-05T17:55:37Z")

</div>

> Originally posted by **nmrao** on February 05, 2024

Alejandro59 ,

This is best case to use [Template Engine](http://docs.groovy-lang.org/latest/html/documentation/template-engines.html) feature of groovy.

Instead of [plc]pattern[plc] =\> use $pattern or $variable

In your case, variables are originalSender, finalRecipient, AP\_Initiator etc

Now the script will just look like below (only replacement part)

```auto
import groovy.text.SimpleTemplateEngine
import java.time.*
//Here define what value needs to be replaced for each variable
def binding = [originalSender: '9928:12341234A', finalRecipient: '9928:12341234B', AP_Initiator: 'POP000106', TimeStampNormalized: System.currentTimeMillis(), TimeStampUTC: Instant.now().atZone(ZoneId.of("UTC"))]

def template = new SimpleTemplateEngine().createTemplate(new File('C:/Templates/Template.xml').getText('UTF-8')).make(binding)
log.info "Updated xml : ${template.toString()}"

```

By the way, you can quickly [run the script](https://ideone.com/WvKSqI) here to see output.

Also wanted to point out why your script is not working.

[plc] - here it will find only p / l / c, but not plc

[,] has to be escaped i.e., [plc]

Then \ has to be escaped again - so finally it will be ‘_**\[plc\]pattern\[plc\]**_’

Check [here](https://ideone.com/4mXCLH#stderr) how it is done.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 7:12pm UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/12 "2024-02-05T19:12:46Z")

</div>

> Originally posted by **Alejandro59** on February 05, 2024

The escaping \[plc\] did the trick.

Many thanks

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 7:30pm UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/13 "2024-02-05T19:30:58Z")

</div>

> Originally posted by **nmrao** on February 05, 2024

Glad, it helped.

Template engine is more simple and elegant in this context. I understand if you can’t change the template to suit template engine.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 5, 2024, 8:21pm UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/14 "2024-02-05T20:21:00Z")

</div>

> Originally posted by **ChrisAdams** on February 05, 2024

nmrao , didn’t know about templating engines in Groovy. Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 6, 2024, 1:36am UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/15 "2024-02-06T01:36:18Z")

</div>

> Originally posted by **nmrao** on February 05, 2024

We all learn over time.

replace or replaceAll is better when single string is to be replaced and direct string. When it has special characters like in this case, it is tricky and don’t understand what is happening though we seem to be correct.

Template Engine is designed for multiple replaces seamlessly and fits into language , simple to use. If you notice the binding, some uses string mapping and some uses programming constructs while replacing such as dates in this case. And the transformation is done in single statement. All we need to do is to create template and binding.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 6, 2024, 5:43am UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/16 "2024-02-06T05:43:25Z")

</div>

> Originally posted by **nmrao** on February 05, 2024

Alejandro59

If you are bound to use existing template, not at liberty to change in order to use template engine, then the script still can be simplified.

You can still define _ **binding** _ map which values needs replaced with, of course, it is no different from the one being shown in case of template engine.

Again this uses regex pattern, \*\*\*/[plc]([\w]+)[plc]/\*\*\*and _ **replaceAll** _ method which you were using earlier.

Here the script goes:

```auto
import java.time.*
def templateString = new File('C:/Templates/Template.xml').getText('UTF-8')
def binding = [
    originalSender: '9928:12341234A',
    finalRecipient: '9928:12341234B',
    AP_Initiator: 'POP000106',
    TimeStampNormalized: System.currentTimeMillis(),
    TimeStampUTC: Instant.now().atZone(ZoneId.of("UTC"))
]
// => Here is the pattern /\[plc\]([\w]+)\[plc\]/ 
templateString = templateString.replaceAll(/\[plc\]([\w]+)\[plc\]/) { match ->
    binding[match[1]].toString()
}

log.info "Updated xml : ${templateString.toString()}"

```

You [try executing](https://onecompiler.com/groovy/423mf8xez) it here quickly.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [February 11, 2024, 3:08pm UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/17 "2024-02-11T15:08:33Z")

</div>

> Originally posted by **richie** on February 11, 2024

nmrao & ChrisAdams

I love it when you two answer posts…i learn loads!

Cheers lads!

Rich

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [October 7, 2026, 5:11pm UTC](https://community.smartbear.com/t/string-replaceall-not-working-in-groovy-script/71/18 "2026-10-07T17:11:47Z")

</div>

Closed on October 7, 2026, 5:11pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
