# Correlation using regex | Java Gatling

**URL:** <https://community.gatling.io/t/correlation-using-regex-java-gatling/8457>\
**Category:** Gatling (Open-Source)\
**Created:** [November 16, 2023, 9:41am UTC](https://community.gatling.io/t/correlation-using-regex-java-gatling/8457 "2023-11-16T09:41:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lathem](https://avatars.discourse-cdn.com/v4/letter/l/bb73d2/32.png) [@Lathem](https://community.gatling.io/u/Lathem)\
**Post date:** [November 16, 2023, 9:41am UTC](https://community.gatling.io/t/correlation-using-regex-java-gatling/8457/1 "2023-11-16T09:41:34Z")

</div>

Hi I am getting error – Failed to build request: \*\*No attribute name \*\*  
**d ‘ID’ is defined**.  
I am using simple regex chcek and saving it in a variable as below:

.check(regex(“[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{9}…(?=)”)  
.findAll().saveAs(“ID”))

I am not defining it anywhere , Can someone help me, I am using JAVA to create Gatling scripts

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [November 16, 2023, 10:21am UTC](https://community.gatling.io/t/correlation-using-regex-java-gatling/8457/2 "2023-11-16T10:21:29Z")

</div>

> I am not defining it anywhere

Yes you are, I guarantee. Please double check for things like `#{ID}`, `${ID}` (deprecated syntax) or `session.getString("ID")`.

---

<div class="post-metadata">

**Author:** ![Lathem](https://avatars.discourse-cdn.com/v4/letter/l/bb73d2/32.png) [@Lathem](https://community.gatling.io/u/Lathem)\
**Post date:** [November 16, 2023, 1:23pm UTC](https://community.gatling.io/t/correlation-using-regex-java-gatling/8457/3 "2023-11-16T13:23:46Z")

</div>

Can you please send me the syntax to define it  
.exec(session → {  
session.getString(“#ReservationID”);  
return session;  
})  
I tried this ,but not working

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [November 16, 2023, 1:54pm UTC](https://community.gatling.io/t/correlation-using-regex-java-gatling/8457/4 "2023-11-16T13:54:55Z")

</div>

Please have a look at the documentation:

- Gatling Expression Language: [Gatling - Expression Language](https://gatling.io/docs/gatling/reference/current/core/session/el/)
- Gatling Session API: [Gatling - Session API](https://gatling.io/docs/gatling/reference/current/core/session/session_api/)

You’re mixing/confusing them and that can’t work.

---

<div class="post-metadata">

**Author:** ![trinp](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/trinp/32/1593_2.png) [@trinp](https://community.gatling.io/u/trinp)\
**Post date:** [November 17, 2023, 4:38am UTC](https://community.gatling.io/t/correlation-using-regex-java-gatling/8457/5 "2023-11-17T04:38:10Z")

</div>

Please modify as this one and test again if it helps you

```auto
.exec( session -> {
     val name = session.set("ReservationID", "your expecting value");
name
})

```

to use it somewhere else in Gatling session, call:

```auto
.exec(
    yourhttp( #{ReservationID} )
)

```

If you are insisting on `getString` rather than `set`, then I may misunderstand your use case tho

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/2X/b/b148e0742de35c6280726cabf3ecd3de2d320f63.png) [@system](https://community.gatling.io/u/system)\
**Post date:** [December 17, 2023, 4:38am UTC](https://community.gatling.io/t/correlation-using-regex-java-gatling/8457/6 "2023-12-17T04:38:37Z")

</div>

Closed on December 17, 2023, 4:38am UTC

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