mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2003
Posts: 325
W
Wolfie Offline OP
Fjord artisan
OP Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
Let's say I want to look for the word "barf" and forms of different spellings like "barph"...

I know that /(bar)(f|ph)/g will get both of those...

How do I detect "baaarrrrfff" though, as an example?

Specifically, I'm trying to make a swear kicker that will use RE's to be a bit wiser for the detection, and the one thing that can evade are repeated letters (or if they type out the word in the form of b-a-r-f or "b a r f").. Any assistance would be appreciated.

grin

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
/b+a+r+(?:f+|p+h+)/g

a+ will get aaaaaaaaaa or a, so that version will catch bbbaaarrrphhhhh.

If you don't need to capture (for later use in \1 or $regml(N)), use the above just to match. If you require the match to be returnable, surround the whole thing with ( ).

/(b+a+r+(?:f+|p+h+))/g


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Aug 2003
Posts: 325
W
Wolfie Offline OP
Fjord artisan
OP Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
what does the ?: do out of curiousity? And would ya happen to know any sites that don't babble excessively and then give 1 or two examples and claim to be a tutorial on RE's? grin

and thanks dude.. I had actually thought of asking you directly (I've noticed your expertise in other posts) but thought that this could help others too if they can make use of any of it.

cool

Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
?: makes a non-capturing subpattern. Try http://www.regular-expressions.info/ and http://www.pcre.org/man.txt

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Additionally, using (?: to make it not capture also means that the regex engine doesn't need to set up a memory structure to hold results, which speeds up the regex somewhat, especially for nested subpatterns - $regml(29).


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Aug 2003
Posts: 325
W
Wolfie Offline OP
Fjord artisan
OP Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
ie, $regml wouldn't hold any of it (the section with ?: in it) or it would be in $regml but not by itself?

...hey, this is useful stuff, I ain't gonna knock what I can learn from it.. And I am still looking over those two sites (Thanks Online).. Getting some nice information from there too.

#81617 02/05/04 05:52 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019


Gone.
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Wolfie: If you do not capture anything with ( ) then $regml will hold nothing at all. This includes those (?: ) sections, they won't be in $regml either. That means that if you DO want $regml to hold something, you have to capture what you DO want with ( ).

FiberOPtics: Be aware that some of those sites might refer to a slightly incompatible version of Regular Expressions. PCRE means Perl-Compatible Regular Expressions. The version that Perl uses is slightly different and so may need some translation or may not work at all in PCRE.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hello,

I'm well aware of this smile

It is even mentioned in some sites like the PHP one that there are differences.

I gave all those sites as they might be useful.


Greetz


Gone.

Link Copied to Clipboard