Reputation: 1863
I want to match parts of a string that start with a certain character (asterisk):
abc*DEFxyz
=> *DEF
abc*DE*Fxyz
=> *DE
, *F
Tried preg_match_all('/[$\*A-Z]+/', $string, $matches);
But it doesn't seem to work. I get *DE*F
on the 2nd example
Upvotes: 0
Views: 55
Reputation: 757
Try:
^[^*]*\*
which says "from the start of the line, skip over all non-asterisk characters and stop at the first"
Extending this:
s/^[^*]*\*(.*)/
Will return the remainder of the string after the asterisk. To include the asterisk, adjust like this
s/^[^*]*(\*.*)/
Here's a great tool for checking your regex: http://gskinner.com/RegExr/
Hope this helps
Upvotes: 1
Reputation: 43235
Change your regex to this :
\*[A-Z]+
Your regex here : [$\*A-Z]+
means a string containing *
and A-Z characters, not mentioning anything about start.
Upvotes: 4