TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Regex Questions

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
mekhami



Joined: 27 Aug 2015
Posts: 2

PostPosted: Thu Aug 27, 2015 8:28 pm    Post subject: Regex Questions Reply with quote

Code:
^.+?(say|ask|boom|bubble|chatter|chime|exclaim|growl|hiss|purr|rasp|ribbit|rustle|think|whisper)((e)?s)? (to )?[A-z]+( in .+?)?\: .+$


I've got this sort of regex. How in the WORLD do I convert this to the tintin regex engine? The conditional stuff after the large array really messes me up.
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Fri Aug 28, 2015 12:19 pm    Post subject: Reply with quote

can you post also some phrase to be filtered ?
Back to top
View user's profile Send private message
mekhami



Joined: 27 Aug 2015
Posts: 2

PostPosted: Fri Aug 28, 2015 2:44 pm    Post subject: Reply with quote

Well. A lot of things. For instance:

You say: Hello
Greg says: Hi
Sam hisses: What?
Darling tells you: Nothing
John seems to say: Blah
Hardy says in dwarvish: Bah humbug.
Jake says to you: I'm from state farm.

What it shouldn't catch:
words like 'A bubble.' 'A boomerang.'
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Mon Aug 31, 2015 5:08 am    Post subject: Reply with quote

you should try to wrap the entire expression with {} to make it work as a normal regexp:

Code:

#var phrase {Sam hisses: What?}
#OK. VARIABLE {phrase} HAS BEEN SET TO {Sam hisses: What?}.
#regexp {$phrase} {{^.+?(say|ask|boom|bubble|chatter|chime|exclaim|growl|hiss|purr|rasp|ribbit|rustle|think|whisper)((e)?s)? (to )?[A-z]+( in .+?)?\: .+$}} {#echo $phrase}


Anyway, I don't think that the expression you posted is correct for all the listed cases, in the previous example it doesn't catch the phrase because of the space and the "[A-z]+" part expected before the ":"
Back to top
View user's profile Send private message
F-3000



Joined: 06 Dec 2010
Posts: 66
Location: Next to polarbear

PostPosted: Fri Feb 26, 2016 9:47 am    Post subject: Re: Regex Questions Reply with quote

mekhami wrote:
Code:
^.+?(say|ask|boom|bubble|chatter|chime|exclaim|growl|hiss|purr|rasp|ribbit|rustle|think|whisper)((e)?s)? (to )?[A-z]+( in .+?)?\: .+$

Here's the regex slightly optimized and fixed:
Code:
^.+? (say|ask|boom|bubble|chatter|chime|exclaim|growl|hisse?|purr|rasp|ribbit|rustle|think|whisper)s?( (to )?[A-z]+( in .+?)?)?\: .+$


Changes explained:

I added space before the list, so that we'll skip comparing the list for spaces, and start from the beginning of a word. Will prevent list matching to flask and such. Minimal benefit, but some regardless.

I removed ((e)?s)? completely, except s?. I'm not native with english, so I might be incorrect with this one, but I thought that "es" does not match with anything else than "hiss" (hisses), thus we really don't need the letter e elsewhere, so I added it behind the hiss, with questionmark: |hisse?|. The questionmark should affect only the letter e in that position. The lack of e at the end of the list impacts every matched string. I also removed the closures around s at the end of the list, because we don't need 'em for a single symbol.

I also added ()? between question mark after list and : to make something like "says:" to work by enclosing everything inbetween to nice MAYBE.

If you need the regex only for matching, not for capturing, you can drop .+$ from the end of the regex.

Then there's lookbehind which could be used to finegrain further, but I don't feel THAT smart today.

As a side note, .+? does not equal to .*. Question mark makes quantifier (like + and *) lazy, as I (re?)learned after posting ma first edit.

Note: If someone knows something better than I about what I wrote, I'm all open for education. Smile

(My source.)

Ps. Thanks to PowerGod and his code, I actually tested the regexes, and they seem to work.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group