I, have a text that reads something like:
....text....
listname: mylistname
....text....
name: John Smith
I am trying to obtain the name of the person, however using preg_match like the following: preg_match('#name:\s\w{0,}\s\w{0,}#', $body, $arrNameMatches)
I get “mylistname”… What can I add to that pattern so that it gets name: as a full word only, hence getting ‘John Smith’?
Add a word anchor before
name:Alternatively, if you are sure that
namewill always occur at the beginning of the input, you can use a “begin of input” anchor, ie^: