SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    May 2007
    Location
    Montreal
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular Expressions PregMatch?

    Hi

    I am wondering hot to search a sentence to see if it has a matching case like the following:

    'I am ANY_WORD_HERE.'

    Basically I need the I am + a word + a period after a word.

    Any ideas?

    I will post anything here if I find it before I get help.

    Thanks,
    Chris

  2. #2
    <?php while(!sleep()){code();} G.Schuster's Avatar
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $sentence 'I am ANY_WORD_HERE.';
    preg_match('/^I am (.*?)\./'$sentence$match);
    print_r($match); 
    One thing: it matches anything until the first period, so "I am a really huge bear." will also match (a really huge bear), while "I am here. Go away" will only match "here" and "I am. You are" will not match.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •