Author Topic: Regex slashes  (Read 449 times)

0 Members and 1 Guest are viewing this topic.

Offline livewirerulesTopic starter

  • Irregular
  • Posts: 44
    • View Profile
Regex slashes
« on: March 19, 2010, 02:37:12 AM »
I need to match text that contain forward slashes
Code: [Select]
/hello
/test
/MyWorks

For eg: i want to match "/hello"?

any help will be appreciated :D

Offline The Little Guy

  • Freak!
  • Posts: 6,103
  • Gender: Male
  • Jinkies!
    • View Profile
    • PHPSnips
Re: Regex slashes
« Reply #1 on: March 19, 2010, 02:55:18 AM »
This works:

Code: [Select]
<?php
$string 
'are you there? /test...';
if(
preg_match("~/hello|/test|/MyWorks~"$string))
echo 'found word!';
else
echo 'word not found';
?>
« Last Edit: March 19, 2010, 02:56:43 AM by The Little Guy »
phpLive - A powerful library that implements many common tasks to make php programming faster. Supports extensions and plugins. Current version: 1.0.0-Alpha
JPG to ASCII Converter | Advanced Image CAPTCHA | Simple User Login | Check If User Is Logged In
http://dreamhost.com (promo code: 8RN4)
$30 off 1 year of hosting
$40 off 2 years of hosting