mhykhh Posted February 28, 2007 Share Posted February 28, 2007 Hi, I'm a beginner when it comes to regex and I'm stuck with a problem involving the character class. Say I have the following pattern: /<my-customtag id=([0-9]+)>([^<\/my\-customtag>]+)<\/my-customtag>/ The pattern above doesn't product any matches even if the haystack is something like - <my-customtag id=1>Some Text</my-customtag> But when I trim the length of the characters inside the character class like: /<my-customtag id=([0-9]+)>([^<\/my]+)<\/my-customtag>/ It works fine... Any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
effigy Posted February 28, 2007 Share Posted February 28, 2007 A character class allows any character inside to be matched; a better approach is: <my-customtag id=([0-9]+)>(.+?)<\/my-customtag> ...or, if you use a preg shorthand and change the delimiter... <my-customtag id=(\d+)>(.+?)</my-customtag> If you want to add specific lengths to a character class, use the {min, max} quantifier. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.