# Cannot use currentLocationRegex (in Java)

**URL:** <https://community.gatling.io/t/cannot-use-currentlocationregex-in-java/6865>\
**Category:** Gatling (Open-Source)\
**Created:** [June 23, 2022, 10:27am UTC](https://community.gatling.io/t/cannot-use-currentlocationregex-in-java/6865 "2022-06-23T10:27:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fatma](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fatma](https://community.gatling.io/u/fatma)\
**Post date:** [June 23, 2022, 10:27am UTC](https://community.gatling.io/t/cannot-use-currentlocationregex-in-java/6865/1 "2022-06-23T10:27:43Z")

</div>

Hello,

Actually I want to get the location from header response, so I’m using currentLocationRegex as mentioned in [Gatling - HTTP Checks](https://gatling.io/docs/gatling/reference/current/http/check/#http-header)

But it seems Eclipse doesn’t accept it, it can’t recognize the function(even the package is already imported).

Here it’s the code that I’m using :

.exec(  
http(“/auth/realms/bhs-ca/login-actions/authenticate?session\_code=”+sessionUrl)  
.post(authURL+“/auth/realms/bhs-ca/login-actions/authenticate?session\_code=”+sessionUrl)  
.formParam(“username”, “\*\*\*\*\*\*\*\*”)  
.formParam(“password”, “\*\*\*\*\*\*\*”)  
.formParam(“reponse\_type”, “code”)  
.headers(headers\_3)  
.check(status().is(200))   
**.check(currentLocationRegex(“session\_state=(.\*)&code=(.\*)”).captureGroups(2).saveAs(code))**  
)

I’ve used before regex to check a value in response body and it worked well!  
Anyone has a solution for that?  
Thank you

---

<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:** [June 23, 2022, 10:36am UTC](https://community.gatling.io/t/cannot-use-currentlocationregex-in-java/6865/2 "2022-06-23T10:36:19Z")

</div>

What doesn’t work exactly? Beware that as you have 2 capture groups, the extracted result is an array of Strings of length 2, so if you want to use Gatling EL to access the values, you’ll have to access by index, see [Gatling - Expression Language](https://gatling.io/docs/gatling/reference/current/core/session/el/#syntax)

---

<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:** [June 23, 2022, 10:37am UTC](https://community.gatling.io/t/cannot-use-currentlocationregex-in-java/6865/3 "2022-06-23T10:37:28Z")

</div>

Also, `.saveAs(code))` is wrong. It should be `.saveAs("code"))`

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [June 23, 2022, 10:54am UTC](https://community.gatling.io/t/cannot-use-currentlocationregex-in-java/6865/4 "2022-06-23T10:54:35Z")

</div>

> [@fatma](#):
>
> But it seems Eclipse doesn’t accept it, it can’t recognize the function(even the package is already imported).

Do you have all the required `import`s?

```java
import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

```

Note that `currentLocationRegex` is a (static) method present in `io.gatling.javaapi.http.HttpDsl.HttpDsl` class.

---

<div class="post-metadata">

**Author:** ![fatma](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fatma](https://community.gatling.io/u/fatma)\
**Post date:** [June 23, 2022, 11:00am UTC](https://community.gatling.io/t/cannot-use-currentlocationregex-in-java/6865/5 "2022-06-23T11:00:25Z")

</div>

Hello

Yeah the reason was the missing static package .

Thank you for the reply!
