regex help

what will be the regex expression to find 'S in the text

'x:\somepath\f\file.txt','Element Type,'x:\somepath\f\file.txt||x:\somepath\f\file.txt’,'453450337','JACK'S Houses’ I','2323314','PRRR','','10/14/14','0073332','','/  /',0

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:

<?php // demo/temp_calmsoul.php


$txt = <<<EOD
'x:\somepath\f\file.txt','Element Type,'x:\somepath\f\file.txt||x:\somepath\f\file.txt’,'453450337','JACK'S Houses’ I','2323314','PRRR','','10/14/14','0073332','','/  /',0

= '/'        // REGEX DELIMITER
. "'S"       // SEARCH STRING
. '/'        // REGEX DELIMITER

if (preg_match($rgx, $txt)) echo 'THERE IS APOSTROPHE S FOUND IN ' . $txt;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dan CraciunIT ConsultantCommented:
This is a job for strpos, straight from the manual page (
$mystring = "'x:\somepath\f\file.txt','Element Type,'x:\somepath\f\file.txt||x:\somepath\f\file.txt’,'453450337','JACK'S Houses’ I','2323314','PRRR','','10/14/14','0073332','','/  /',0";
$findme   =  "'S";
$pos = strpos($mystring, $findme);

// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
} else {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";

Open in new window

Unlike regex, this will tell you where the string was found.

Ray PaseurCommented:
@Dan: I always wonder about these sorts of questions.  So many people insist on using regular expressions when there are simpler alternatives, or insist on using regular expressions when they are not capable of doing the job.  I agree that strpos() or maybe stripos() is a better solution for the one-and-only one test example that we see here.  But the author asked for regular expressions.  So I'm never sure whether the question is written that way so that the author can learn about regular expressions, or the author assumed regular expressions were needed, when the right answer was probably found in the PHP string processing functions.  It's a conundrum!
Dan CraciunIT ConsultantCommented:
@Ray: for once, we exchanged roles: I advise on not using regular expressions :)

The reason: I like 'em and became proficient. But I "solved" some problems for co-workers/friends that don't understand them and now I have to take care of any changes to the code.

Bottom line: don't use regular expressions when a simple find would do. They're very powerful, but that power comes with great responsibility :)
Ray PaseurCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.