hi,

i am facing the problem with reuglar expressions. my requirement is if type the word like $var in a input field and select the EXACT WORD radio button and i click the search button then i want to display all files with the word $var all in my directory. using reuglar expressions in php.

i have wirtten the code here.just i am sending only preg_match_all function.but my preg_match function is wrong. pls help me in this.

my code is :

if ($action == 'SEARCH_AND_REPLACE')
{
if ($strpos($line, $pattern) === false)
{
}
else
{
$temp_line = $line;
if(strstr($pattern,'$_')){
preg_match_all("/[[a-zA-Z](.*)\]/", $line, $out, PREG_OFFSET_CAPTURE);
}
else if(strstr($pattern,'$'))
{
$pattern_type=trim($_POST);
if($pattern_type == 'EXACT WORD')
{preg_match_all("/[a-zA-Z](.*) \=/", $line, $out,PREG_OFFSET_CAPTURE);
}
else
{
preg_match_all("/[a-zA-Z](.*)/", $line,$out,PREG_OFFSET_CAPTURE);
}
}
}

explanation :

In the above the code $pattern means which i enter the value in input field(Ex:$var).
$line means all files in my dir.

thanks in advance,

swap.

Member Avatar for iamthwee

I wouldn't use reg ex.

I would just look for a substr within the string.

hi,

wht u r saying i am not getting.actually my problem is when i search the particular world with a special character then its not working.
i have written my regular expression like this:

preg_match_all("/\b$var\b/",$line,$out,PREG_OFFSET_CAPTURE);

explanation:$line conations all files in my dir.

i am searching the particular word(i.e.,$var) all files in my dir.

here my preg_match_all() function is wrong for the special characters.

pls help me.

thanks in advance,

swap.

Member Avatar for iamthwee

You need to give a better example than that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.