将约束添加到点球路径参数

时间:2019-03-29 09:51:29

标签: ruby-on-rails regex routes constraints

我有以下路线:

import pandas as pd
import numpu as np

df = pd.DataFrame({'name':'A B C D E'
                   .split(),'ids':['147 616 813','51 616 13 813','776','51 671 13 813 1092','13 404 492 903 1093']})

#Every input of i_d to functions in int
#to get indexes where id occurs
def rows(i_d):
    i_d = str(i_d)
    pattern1 = "[^0-9]" +i_d+"[^0-9]"
    pattern2 = i_d+"[^0-9]"    
    pattern3 = "[^0-9]" +i_d 

    mask = df.ids.apply(lambda x: True if (len(re.findall(pattern1,x)) > 0) | (len(re.findall(pattern2,x))) | (len(re.findall(pattern3,x)) > 0) else False)

    return df[mask].index.tolist()

#to get other ids occuring with the id in discussion
def colleagues(i_d):
    i_d = str(i_d)

    df.loc[rows(i_d),'temp'] = 1
    k =list(set(df.groupby('temp').ids.apply(lambda x: ' '.join(x)).iloc[0].split()))
    k.remove(i_d)
    df.drop('temp',axis=1,inplace=True)

    return k

#to get row indexes where 2 ids occur together
def third(i_d1,i_d2):
    i_d1 = str(i_d1)
    i_d2 = str(i_d2)

    common_rows = list(np.intersect1d(rows(i_d1),rows(i_d2)))
    if len(common_rows) > 0:
        return print('Occured together at rows ',common_rows)
    else:
        return print("Didn't occur together")

我想要一个约束,只有get lib/2/subscriber:*params, to: 'lib2#subscriber_req' params时,此路由才匹配。我想要它匹配

/\d+\//

但不是

lib/2/subscriber:1256/bla/blabla

我阅读了this文档。我写了这条路线:

lib/2/subscriber:some_text1256/bla/blabla

但这不起作用。

通常,我不知道如何处理GLOBS约束。一些链接将非常有帮助。

1 个答案:

答案 0 :(得分:0)

我不明白为什么您会认为/\d+\//会区分:

  • lib/2/subscriber:1256/bla/blabla
  • lib/2/subscriber:some_text1256/bla/blabla

它们都与该正则表达式匹配。如果要匹配第一个URL的params部分,而不是第二个URL的部分,那么也许可以使用:

/\A\d+\//