正则表达式,如果它不包含特定字符,则获取完整字符串?
I need help with a regular expression that will find matches in the strings below:
myDOG_test
myCAT_test
Basically, I want to return 'DOG' or 'CAT' from these paths.
Then I have similar strings (all start with 'my') that don't contain the underscore AFTER the value I want, and in that case I just want to return the FULL string -- in a match group.
myCentralReports
myDEMO3
This is the REGEXP that I have so far:
.*?my(.*?)\_.*
This correctly puts CAT & DOG in the matching group, but I'm having problems matching the other 2 strings. Obviously I left the hardcoded underscore in there just to show you what I started with -- but I need to modify this for the other case. Any help is appreciated! Thanks.
doulao2128
2011/01/28 16:14- regex
- php
- 点赞
- 收藏
- 回答
满意答案
3个回复
