mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2012
Posts: 5
D
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jun 2012
Posts: 5
Been trying to figure this one out and it's stumped me.
Trying to find a regex that will match 'word' but only if there is either a space, nothing, or punctuation on either side.
So, if the word was cat:
"cat" matches
" cat" matches
" cat? " matches
"scatting" doesn't match
I tried "[^a-zA-Z0-9] $+ %word $+ [^a-zA-Z0-9]" but that still demands a space either side. I know it sounds simple, but I can't figure it out. Any help will be appreciated. Thanks! smile

Last edited by dreadofmondays; 05/06/12 07:12 AM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Take a look at word boundaries in regex. \b and \w. If you want to match an actual space, there is \s, but I don't think that's what you need for what you're doing.

Example: /\bword\b/g

That will match the examples you gave.


Invision Support
#Invision on irc.irchighway.net
Joined: Jun 2012
Posts: 5
D
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
D
Joined: Jun 2012
Posts: 5
Thanks, that did the trick. smile


Link Copied to Clipboard