FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Regular Expression Help
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Regular Expression Help [message #179337 is a reply to message #179335] Mon, 08 October 2012 10:03 Go to previous messageGo to previous message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma:
Senior Member
On Oct 8, 5:20 am, Scott Johnson <nooneh...@chalupasworld.com> wrote:
> I have two possible values I need to match as the same.
>
> Name/11 (This one is pulled from the source DB)
> Name/11* (This is what I need to match to with or without the (*))
>
> The pattern base name is pulled from a DB so I need to find a way to do
> this pragmatically.
>
> Now some of the names have a forward slash / so I am using hash mark #
> as a delimiter.
Safer than this is to use preg_quote().

>
> I was able to find the "Name/11" using
>
> #^Name/11#
>
> or more specifically;
>
> $value = "Name/11";
> $pattern = "#^" . $value . "#";
>
> But as for the (*), no glory.
> I originally tried
>
> #^Name/11?*#
> #^Name/11\*#
> #^Name/11.*#
The middle one will sepcifically match "Name/11*" but it will not
match "Name/11".
Since ? means "match 0 or 1 occurrences", "Name/11\*?" will match what
you want. However, it will also match "Name/11e". To match precisely
what you have described, you need something like this:
$value = "Name/11\*?";
$match_value1 = "Name/11";
$match_value2 = "Name/11*";
$match_value3 = "Name/11t";
$pattern = "#^$value$#";
echo preg_match($pattern, $match_value1);
echo preg_match($pattern, $match_value2);
echo preg_match($pattern, $match_value3);
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to run a batch file using PHP?
Next Topic: dll load problem
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 12 21:56:09 GMT 2024

Total time taken to generate the page: 0.04904 seconds