Hello,
I have not had a huge amount of experience with regular expressions.
Any help you can give is greatly appreciated.
I have an input file like this:
Name: Bob, Age: 20, Details: Likes chocolate
Hates lettuce, Location: London
Name: James, Age: 42, Details: Sometimes goes swimming, Location: New York
Name: Jenny, Age: 15, Details: Eats out every night
Dislikes cats
Loves Dogs, Location: Tokyo
Name: Henry, Age: 65, Details: Hate rain
Loves sunshine
Name: Julian, Age: 34, Details: Has too many CDs, Location: Paris
I want to match some details using the regular expression and preg_match_all:
/Name: (?<name>\w+), Age: (?<age>\d+),.*?Location: (?<location>.*?)/is
Where it holds the values of name, age and location, over multiple lines and being case insensitive.
However, the above regular expression will match the below as one entity because "Henry" does not have a location.
Name: Henry, Age: 65, Details: Hate rain
Loves sunshine
Name: Julian, Age: 34, Details: Has too many CDs, Location: Paris
Is is possible to have it so that the match ".*?" cannot contain the string "Name" (which would then prevent it from carrying on to into another person's entry).
eg:
/Name: (?<name>\w+), Age: (?<age>\d+),.*?[^Name]Location: (?<location>.*?)/is
However, I realise this is not correct as [^Name] matches N, a, m or e
I know it's possible for a single character, but how about a string?
Thank you for any help you can give,
Ralf