Re: REGEX query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for the options David.

I think I'll go for the last option as I'm determined to get to grips with REGEX, and your first choice of REGEX won't work for me as the 'RV-6' bit can be too variable with what it contains, whereas the \(EX\) bit IS more constant...it's only the EX bit that changes.

I knew I had to to escape some characters but got confused as to how many times to do each one.
I have tried using your example as follows:

$postScriptData =preg_replace("/\\\(.*?\)\\/","",$postScriptData);

and get the following error:
Warning: No ending delimiter '/' found in...

Any suggestions?

Cheers
Alexis


David Tulloh wrote:

I assume that the text inside can change around a fair bit.  If the
string is of a fixed with or simple format you can just use substr() and
friends, it's simpler and faster.

That said, there is really two approaches that I can see with this string.

You can match on the spaces to extract the 'RV-6', something like
'/\s\S+\s/' should do the trick, that pulls out some non-whitespace
characters from between two whitespace characters, including the
whitespace characters.  Then just add the () on again afterwards.

The other approach would be to use preg_replace to get rid of the \(EX\)
portion by replacing it with an empty string.  Personally I would
probably use the first technique as I generally don't like using replace
functions in this way.  A pattern which should match is '/\\\(.*?\)\\/',
the mess of \ is because \ ( and ) all need to be escaped with a \.


David

phplists wrote:

Hi,

I'm still trying to get to grips with REGEX and have hit a hurdle with
the following:

I have this bit of text:
(\(EX\) RV-6 )

I want to remove the '\(EX\)' part of it
so leaving just: ( RV-6 )

Any suggestions would be most appreciated.

Thanks
Alexis






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux