How to get values from within parentheses

Post Reply
jbrumble
Posts: 13
Joined: Sat Jan 09, 2021 4:31 am

How to get values from within parentheses

Post by jbrumble »

Hello Folks,

I'm quite new and have run into a bit of a roadblock. I'm attempting to get the value of the current and max values of the characters stats in the following line:
Sheynna < PC (Ne1) - 25(25)H 108(108)M 122(122)V> (Leader)

The issue I am running into is that the parentheses in the above line seem to cause issues with the code. The closest I am getting is:
^ Sheynna < PC (.*) - (\d+)((\d+))

matches[3] returns as 2 here instead of 25.

I'd appreciate any guidance you folks could offer.

Thank you!

User avatar
demonnic
Posts: 720
Joined: Sat Dec 05, 2009 3:19 pm

Re: How to get values from within parentheses

Post by demonnic »

try
^Sheynna < PC \((.*)\) - (\d+)\((\d+)\)H (\d+)\((\d+)\)M (\d+)\(\d+\)V>

The parantheses that are actually in the line need escaping, because of that that first (.*) is matching (NE1), then the next match is 2, and the one after 5, because that's the only way it can parse that to make the regex match. The one I pasted above should hopefully capture the whole line and get your stats into the matches table.

Also, regex101.com can be a big help for making and testing these kinds of patterns.

jbrumble
Posts: 13
Joined: Sat Jan 09, 2021 4:31 am

Re: How to get values from within parentheses

Post by jbrumble »

Thank you very much for the response! It's working perfectly!

Post Reply