Is there a way to use regexmatches and select a grouping?

Discuss and share scripts and script files...
Post Reply
mydarkpassenger
Posts: 31
Joined: 19 Apr 2014 19:39

Is there a way to use regexmatches and select a grouping?

Post by mydarkpassenger »

I'm trying to use regexmatches and I want to have pull groups pulled from the result. I'm aware that you can put these in groupings and with regexreplace you can replace values from the result but I'm wondering how can I just get the results from this list into something I can grab? For example, I'm trying:

$name = "abc-123";
$search = regexmatches($name, "^([a-z]+)(-)?([0-9]+)", ",");

Can I use something like
msg gettoken($search, "1");
to get a result?

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Is there a way to use regexmatches and select a grouping

Post by bdeshi »

that would be a boon to have!
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

mydarkpassenger
Posts: 31
Joined: 19 Apr 2014 19:39

Re: Is there a way to use regexmatches and select a grouping

Post by mydarkpassenger »

SammaySarkar wrote:that would be a boon to have!
Figured out a way. However, I was hoping for something cleaner. It will match but unfortunately you need to account for the whole string to match because it just replaces contents you find. Unmatched content is left intact:

$name = "abc-123";
$results = regexreplace($name, "^[\[\s]*([a-z]+)[-]?([0-9]+)", "$1|$2");
msg gettoken($results, "1", "|");

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Is there a way to use regexmatches and select a grouping

Post by highend »

That doesn't use regexmatches (which you've asked for) :P

What are you trying to achieve here?

Code: Select all

[\[\s]*

Code: Select all

\s*
is enough.
One of my scripts helped you out? Please donate via Paypal

mydarkpassenger
Posts: 31
Joined: 19 Apr 2014 19:39

Re: Is there a way to use regexmatches and select a grouping

Post by mydarkpassenger »

highend wrote:That doesn't use regexmatches (which you've asked for) :P

What are you trying to achieve here?

Code: Select all

[\[\s]*

Code: Select all

\s*
is enough.
Sorry I use a brackets and space in my names ex. abc-123 to [ abc-123 ] to try and make them cleaner. I didn't specify it in my comment because I was trying to keep it simple. Then I was removing it from my example and forgot the beginning.

Post Reply