Regex and functions

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

User avatar
Irrlicht
Dragon
Posts: 426
Joined: Mon Feb 09, 2009 10:53 am

Re: Regex and functions

Post by Irrlicht »

I was exactly looking at that example, but how come the [h: id = strfind("this is a test", "(\\S+)\\s(\\S+)\\s*")] doesn't return 3 matches, rather than 2?
The third, which would actually be the second, should be "is a ", since it is a non-whitespace string followed by a whitespace, followed by another non-whitespace string, followed/not followed by another space.
Is it that when a part has been parsed, it looks for the next one, not caring for other parts that cross the already parsed one?
"There are many ways my Son, to find where the souls of Demons remain...
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Regex and functions

Post by aliasmask »

Personally, I hate that example. For one, it doesn't explain it. As to why there are only 2 matches is because once a part of the string matches you can't use any part of that string to make another match. So, match 1 is "this is " and match 2 is "a test". "is a " could be have been a match but is already a part of match 1.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Regex and functions

Post by wolph42 »

Personally, I hate that example.
that example had been there for ages I just added the explanation. But feel free to rewrite it or even better add another.

And indeed matches cannot overlap

User avatar
Irrlicht
Dragon
Posts: 426
Joined: Mon Feb 09, 2009 10:53 am

Re: Regex and functions

Post by Irrlicht »

On the matter of adding examples, is it possible to add to the wiki a "for real dummies" section of sort? I was considering trying to write up some of my learnings in a less technical way so that other people who aren't too familiar with various aspects of programming (such as regex) could get their heads on them a bit more easily. As well as further explanations for certain functions for which the wiki cuts it too short.
"There are many ways my Son, to find where the souls of Demons remain...
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Regex and functions

Post by wolph42 »

Irrlicht wrote:On the matter of adding examples, is it possible to add to the wiki a "for real dummies" section of sort? I was considering trying to write up some of my learnings in a less technical way so that other people who aren't too familiar with various aspects of programming (such as regex) could get their heads on them a bit more easily. As well as further explanations for certain functions for which the wiki cuts it too short.
feel free to do so. If you don't have wiki access, pm craig to add you.

User avatar
Irrlicht
Dragon
Posts: 426
Joined: Mon Feb 09, 2009 10:53 am

Re: Regex and functions

Post by Irrlicht »

Done, thanks.

And I also managed to get my macro to work as I wanted (quite a sweat, doing it).
Well, after aliasmask provided those bits of regex, I only had to add a tiny piece more... "(\\d+)" to get the numbers in XdY expressions and both "[+]+", "\\+" and "[-]+", "\\-" (since I divide the XdY expressions from all the +/-Z, I put all of these in another string, so I use those pieces of regex to change the occasional "+++" or "---" to a single "+" or "-").
But surely I got a way better understanding of regex and now it doesn't look anymore like censored bad words in Mickey Mouse's comics.

Thanks.
"There are many ways my Son, to find where the souls of Demons remain...
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."

Post Reply

Return to “Macros”