Newb question

jocmelmul
Posts: 2
Joined: Mon Feb 01, 2010 1:33 am

Newb question

Post by jocmelmul »

Where can I find a list of what regex... bits, match to what text?

Since that probably didn't make sense, I know that \d+ is a number \w+ is a word. I want to know what else I can match.

Also, how do I tell my trigger that a certain character is not part of a regex? If there's a number in parentheses in what I want to match, how do I let it know to ignore the outside set? Say I want to match (63) and have it capture the 63. ((\d+)) doesn't seem like it would work.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Newb question

Post by Heiko »

http://www.regular-expressions.info/reference.html

Mudlet is using the PCRE regex engine.

jocmelmul
Posts: 2
Joined: Mon Feb 01, 2010 1:33 am

Re: Newb question

Post by jocmelmul »

That was exactly what I needed!!! Thankyouthankyouthankyou!

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Newb question

Post by Vadi »

\((\d+)\) will work. \ before a special character will ignore it, so \( will match the literal opening bracket.

Ilithyia
Posts: 43
Joined: Wed Mar 10, 2010 11:04 pm

Re: Newb question

Post by Ilithyia »

I have another newb regex question, so I decided to revive this thread instead of creating another similar one.

What's the difference between (\w+) and (\w*)? I know that 'w' is for words. I'm more confused concerning the '+' and '*'. Looking at a perl regex tutorial, it said that they specify repetition and '*' matches 0 or more times and '+' matches 1 or more times. I'm not really sure what that explanation means, nor when it is best to use one or the other.

Thanks for your assistance!

naftali
Posts: 138
Joined: Wed Jan 20, 2010 8:42 pm

Re: Newb question

Post by naftali »

\w* will match "", "a", or "aba"
\w+ will match all of those except for "" - it needs at least 1 word-type character

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: Newb question

Post by demonnic »

And so you can use \w* for capturing optional words/alphanumeric char. And use \w+ for words/alphanumeric char which absolutely must be there.

(\w+) is here

Would match on

Demonnic is here.

But would not match on

is here

even with the space in front of it.
(\w*) is here

Would match on both of those, but would require the space in front of "is here" ... a truly optional regex would be

(\w*)\s*is here


So that the space is also optional.

Ilithyia
Posts: 43
Joined: Wed Mar 10, 2010 11:04 pm

Re: Newb question

Post by Ilithyia »

Ok, thanks! That definitely cleared things up!

naftali
Posts: 138
Joined: Wed Jan 20, 2010 8:42 pm

Re: Newb question

Post by naftali »

in Demonnic's example, the best way to do that last regexp would probably be:

Code: Select all

\w*\s?is here
because ? matches 1 or 0 occurrences. As Demonnic wrote it, it would also match this:

Code: Select all

Demonnic               is here
Which may not be what you're looking for.

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: Newb question

Post by demonnic »

This is true.. I was just focusing on the difference between + and *. heh

Post Reply