FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

PHP Regex

 


Ironz
hey,

i have a regular expression which is written in C# and want to transform it to php:

Code:
pattern = @"(?<1>.*?)\#(?<2>.*?)\#(?<3>.*?)\*";
Match NameMatch = Regex.Match(source,pattern);

the source i wanna match is something like this:

source = "First#Second#12,345*Ano-ther#Also_another#45,678,548*";

it should return:
1: First
2: Second
3: 12,345

and another match:
1: Ano-ther
2: Also_another
3: 45,678,548


i've searched several places but i couldn't make an equivalent for that expression in php, i'm looking to get the same results (several matches with groups inside each match).

Can someone plz help me out with this?
Nyizsa
So you need to get substrings from a string using a predefined delimiter. I think you need the explode() function, and don't need a regex at all. Try something like the following:
Code:
$sections=explode('*',source);
$values=explode('#',$sections[n]);

So you can select which value of which section is to be printed.
I hope it helps!
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.