I need the regex expression to match everything from beginning till I encounter one of these characters ; or [ or { or ( In case these characters are开发者_如何学编程 not there then the whole word needs to be matched..
I am using preg_match("/(.*?)(?=(;|\[|\(|{|))/", $word , $val);
The first group should be there as I need the matched value in $val. This is php. Can somebody please help me with this?
preg_match("/^([^[{(;]*)/", $word , $val);
"/(.*?)[;\\[\\{\\($]/"
should do the trick and be a lot easier. Note that you'll have to escape characters that have special meanings in regular expressions. $
matches the end of the line/string (depending on parameters).
Edit: Think Anomie's solution might even be a tid bit faster due to only matching one sub expression.
精彩评论