Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Regex Help

Name: Anonymous 2010-09-13 6:49

I am fairly new to perl and even newer to regular expressions, so if you can improve on this at all go on ahead. However, that isn't really why I came here. Basically, I want it to return true if the word(s) after "going/gonna (to)" equal either bed, sleep, nap or rest. I can't get it to work and whenever it comes close to working, it just returns true for any following word, which is not what I want.

I have this:


if($arg =~ /^I( am|'m)? go[naing]?([ to]*) /i)
{
# some code here
}


Any help is appreciate and again, if you can improve this at all, please do.

Name: Anonymous 2010-09-13 6:59

Read SICP

Name: Anonymous 2010-09-13 7:08

if($arg =~ /^I(?:'m| am) go(?:ing|nna) to (?:bed|sleep|nap|rest)/i)

IHBT

Name: OP 2010-09-13 7:13

>>3
You really haven't, but I can't thank you enough. I'll take this and learn from it.

<3

Name: Anonymous 2010-09-13 10:39

#!perl

my $s_Text = shift;
print "Testing for '$s_Text'\n";
my $b_Match = ($s_Text =~ /.*(going|gonna|gonna to|)\s+(bed|sleep|nap|rest).*/i)?1:0;

print $b_Match.$/;

Name: Anonymous 2010-09-13 10:41

>>5

my $b_Match = ($s_Text =~ /.*(going|going to|gonna|gonna to)\s+(bed|sleep|nap|rest).*/i)?1:0;

Name: Anonymous 2010-09-13 10:58

>>5,6
That will never match. .* will ensure that. ``Gona to'' doesn't make sense either. Also code] tags.
shift =~ m/go[inga]{3}(\s+to)?\s+(bed|sleep|nap|rest)/i;
print "Don't you dare $2.\n";

Name: Anonymous 2010-09-13 13:06

I'm gonna to bed
Maybe you should to English first.

Name: Anonymous 2010-09-13 14:02

>>7
That will never match. .* will ensure that.
u incompetent?

Name: Anonymous 2010-09-13 15:23

>>9
It'll be at the end of the string by the time it looks for that first going.

Name: Anonymous 2010-09-13 15:27

http://oreilly.com/catalog/9780596528126

Buy it, read it. It's expensive and may seem like overkill, but you need it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List