i want to retrieve following urls with a regex:
 HREF="http://www.getty.edu/vow/TGNFullDisplay?find=&place=&nation=&english=Y&subjectid=7009830"
 HREF="http://www.getty.edu/vow/TGNFullDisplay?find=&place=&nation=&english=Y&subjectid=7009830&ptype=PF"
the difference is the ending. the first one omits the &ptype=PF and the last one includes it.
at the moment im using this pattern:
 protected $uriPattern = '/http:\/\/www\.getty\.edu\/vow\/.*?\?find=&plac开发者_JAVA技巧e=&nation=&english=Y&subjectid=......./i';
but that works only for the first one.
i wonder how the regex pattern would look like for the preg_match_all to match both of them. thanks for help.
If there is an optional part in the strings you are matching, you can add (optional)?, in your case (&ptype=PF)?.
Try this
protected $uriPattern = '/http:\/\/www\.getty\.edu\/vow\/.*?\?find=&place=&nation=&english=Y&subjectid=.......(&ptype=PF){0,1}/i';
I was going to suggest the more succinct
"/http://www\.getty\.edu/vow/TGNFullDisplay\?find=&place=&nation=&english=Y&subjectid=.+(&ptype=PF)?/i"
The forward slashes are not special in either PHP nor RegEx, and thus do not need to be escaped, and the ID could be a different length.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论