tags:

views:

45

answers:

2

Hi,

I'm new to PHP and generally regular expressions. I have to match words that contains strings like word[0-9]* = any string here . How do I write a regex for this. So far I have come up with this but it doesnt seem to find the strings properly.

$regexp = "word[0-9]* = [A-Z](.*)[a-z]";

How would I correct the above expression?

Thanks in advance

+2  A: 
word[\d]* = (.*)

That?

preg_match('/word[\d]* = (.*)/', $string, $matches);

This is assuming you want to capture the string after the '='.

Gazler
+2  A: 

I don't understand your way of matching "any string here". Instead you could try this:

^word[0-9]+ = .*$

In PHP you also need to add delimiters:

"/^word[0-9]+ = .*$/"
Mark Byers
Hi Thank you. I just had to escape the negation and it works perfectly.. Thanks a lot!
Mahadevan S
You are welcome.
Mark Byers
Actually I'm getting an array which is populated with all these matches followed by the rest of the page contents ( I'm trying to parse a html page ). Is there any way I can get only the array of words ?
Mahadevan S