Search code examples
javascriptregexdigits

How can this regular expression corrected to extract series and image numbers from reports?


I'm looking to extract information from the following text examples:

"(series 602 image 91)" or " series number 89 and image number 34" or "Series # 4, Image # 14" and looking to extract the numeric as value and series and image tags respectively.

My current attempt: ([(,]series *{\}d+?[,/ ]* *image* {\}d+(/{\}d+)?[),]) *? on_img


Solution

  • Use

    /series.*?([0-9]+).*?image.*?([0-9]+)/i
    

    See proof. The .*? pattern will match any characters between your words, but as few as possible, so the captured numbers will be closest to those words.