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 Link to comment https://forums.phpfreaks.com/topic/40491-character-class-length-limit/ 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. Link to comment https://forums.phpfreaks.com/topic/40491-character-class-length-limit/#findComment-196157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.