skip to Main Content

This is my regex location for nginx.

location ~ "^/live/midrate/v1/rates/((?:[A-Z]{6})-(?:SPT|ON|W[1-3]|M(?:[1-9][0-9]?)|Y[2-5])-(?:[DO])-(?:[ON]))$"

The request URI is

live/midrate/v1/rates/GBPUSD-SPT-D-O

and result is

Match found  Capture Groups 1: GBPUSD-SPT-D-O 2:  3:  4:  5:  6: 

firstly I want to have 1 group instead of multiple groups which are empty now and I need to support comma-separated with same pattern.

live/midrate/v1/rates/GBPUSD-SPT-D-O,EURUSD-M1-D-O,EURGP-SPT-O-O

and the response should be

Match found  Capture Groups 1: GBPUSD-SPT-D-O,EURUSD-M1-D-O,EURGBP-SPT-O-O

2

Answers


  1. Chosen as BEST ANSWER

    I tried this one as well and it works.

    ^/live/midrate/v1/rates/((?:([A-Z]{6})-(SPT|ON|TN|W[1-3]|M[1-9][0-9]?|Y[2-5])-([DO])-([ON]),?){1,})$
    

    DEMO


  2. The general rule for capturing a comma-delimited sequence of a pattern is

    (pat(?:,pat)*)
    

    where pat is the pattern for a single iteration.

    So in your case it would be:

    ^/live/midrate/v1/rates/((?:[A-Z]{6})-(?:SPT|ON|W[1-3]|M(?:[1-9][0-9]?)|Y[2-5])-(?:[DO])-(?:[ON])(?:,(?:[A-Z]{6})-(?:SPT|ON|W[1-3]|M(?:[1-9][0-9]?)|Y[2-5])-(?:[DO])-(?:[ON]))*)$
    

    DEMO

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search