Page 1 of 1
Is there a way to use regexmatches and select a grouping?
Posted: 01 Jul 2015 17:50
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?
Re: Is there a way to use regexmatches and select a grouping
Posted: 01 Jul 2015 17:52
by bdeshi
that would be a boon to have!
Re: Is there a way to use regexmatches and select a grouping
Posted: 01 Jul 2015 18:32
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", "|");
Re: Is there a way to use regexmatches and select a grouping
Posted: 01 Jul 2015 18:37
by highend
That doesn't use regexmatches (which you've asked for)
What are you trying to achieve here?
is enough.
Re: Is there a way to use regexmatches and select a grouping
Posted: 02 Jul 2015 12:52
by mydarkpassenger
highend wrote:That doesn't use regexmatches (which you've asked for)
What are you trying to achieve here?
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.