Issue with regex code

Hi community,

I need to find one of two words, “nominal” or “arrété” (yes, because i use putty!)

normaly it’s two results, sometimes it might be this :

login as: server
server@IP's password:
Last login: Fri Jun  7 09:43:34 2019 from IP
[server@app-test-2 ~]$ rcserver status
Etat de server : mode nominal

Or :

login as: server
server@IP's password:
Last login: Fri Jun  7 09:43:34 2019 from IP
[server@app-test-2 ~]$ rcserver status
Etat de server : arrêté

I used this :

((?:^|\W)nominal(?:$|\W)|(?:^|\W)arrété(?:$|\W))

PS: the result must be only “nominal” or “arrété” not both of them, since it depens on the if it’s running or not.

Any sugestions ? Thanks

Up Up some help guys !

Hey man if you want to find both, you need to have the global flag. Ex: /((?:^|\W)mode nominal(?:$|\W)|(?:^|\W)arr▒t▒(?:$|\W))/g
the last letter g is the global flag. I wonder if you already tried it?

1 Like

No, i haven’t. The thing here is that sometimes i can find nominal or arrété never both on same time.

So i’m looking for a regex code, which can show nominal if it find it or arrété if it’s find it…

try to use the global flag and see if it works.

Same result as before

here is my code, and it works. I am not sure what is the case here. May be the online regex testing is not correct?

let pattern = /((?:^|\W)mode nominal(?:$|\W)|(?:^|\W)arrite(?:$|\W))/g;
let str = `login as: server
server@IP's password:
Last login: Fri Jun  7 09:43:34 2019 from IP
[server@app-test-2 ~]$ rcserver status
Etat de server : mode nominal
login as: server
server@IP's password:
Last login: Fri Jun  7 09:43:34 2019 from IP
[server@app-test-2 ~]$ rcserver status
Etat de server : arrite
`;
let a = str.match(pattern);
console.log(a);

the output gonna be

[ ' mode nominal\n', ' arrite\n' ]

It doesn’t give me same result, infact it gives twice same result :

Match 1
Full match	111-125	 nominal
Group 1.	n/a	 nominal
Match 2
Full match	138-146	 arrété
Group 1.	n/a	 arrété

what challenge or section is that you working on. I’ll check out to see what I can do.

It’s for a project, i’m working on…

Uhm… what’s up with the special symbols?

What exactly are you trying to capture?

If you’re just trying to match those two words only…

let re = /Etat de server : (?<server_state>arrite|mode nominal)/;
const { server_state } = str.match(re).groups;
console.log(server_state);
1 Like

When I read your question (in chrome mobile) “arrite” shows up oddly with two special characters instead of the last two vowels. So it’s worth checking if your problems are to do with encoding, either in your code or whatever tool you’re using to test your regex.

Hey @kerafyrm02

I tried yours it doesn’t quite work…

@rjk

Yes, because of putty, i just corrected that

Actualy it gives me two results “group” and “full match”

I’m trying to use something like this :

(?<=Etat de sba : )(arrété|nominal)

@kerafyrm02

Oh, i see what you mean, infact i’m not coding, i’m using UiPath, so i’m trying a regex code that works on it, that’s why. For the group, i don’t know how to use it on the UiPath.

This one works, thank you