Re: REGEX query
| From: | David Tulloh | Date: | Sat, 04 Feb 2006 05:25:16 +0000 |
| Subject: | Re: REGEX query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-229867@lists.php.net to get a copy of this message | ||
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
>