Py学习  »  Always Sunny  »  全部回复
回复总数  4
7 年前
回复了 Always Sunny 创建的主题 » 考虑elasticsearch查询中的每个单词

不确定这是否能完成你的工作,但是这样试试- term 里面 must

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "f1": "lorem ipsum quid"
          }
        },
        {
          "term": {
            "f2": "lorem ipsum quid"
          }
        },
       {
          "term": {
            "f3": "lorem ipsum quid"
          }
        }
      ]
    }
  }
}
7 年前
回复了 Always Sunny 创建的主题 » python3.6如何从.txt中正则化URL?

一种方法是使用regex lookbehind和lookahead在 = 以前 .

import re

regex = r"(?<==)(.*)(?=\.)"

test_str = "\"URL=http://example.net\""

matches = re.finditer(regex, test_str, re.MULTILINE)

for matchNum, match in enumerate(matches, start=1):

    print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))

    for groupNum in range(0, len(match.groups())):
        groupNum = groupNum + 1

        print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
7 年前
回复了 Always Sunny 创建的主题 » python正则表达式-提取浮点模式

如果要匹配多个实例,只需添加 g 另一方面,它只匹配单个实例。 REGEX

(?<=:)\s?([\d,]*\.\d+)

对于python,

# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility

import re

regex = r"(?<=:)\s?([\d,]*\.\d+)"

test_str = ("\n"
    "    💵Soles in mDm : 2864.35⬇\n"
    "    soles MDM: 2,864.35\n"
    "    Soles in mdm :2,864.355\n")

matches = re.search(regex, test_str, re.IGNORECASE)

if matches:
    print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))

    for groupNum in range(0, len(matches.groups())):
        groupNum = groupNum + 1

        print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.group(groupNum)))
7 年前
回复了 Always Sunny 创建的主题 » yii2的mongodb集合-获取嵌套数组的所有内容

让我们用这种方法 foreach() ?

<?php
$json = '[{"_id":"123","books":[{"author":"John","title":"The Book"},{"author":"Smith","title":"Something!"}]},{"_id":"321","books":[{"author":"John","title":"The Book"}]}]';

$array = json_decode($json, 1);
$ids = [];
foreach($array as $v) {
    foreach($v['books'] as $book){
        $books[] = $book;
    }
}
echo json_encode($books);
?>

输出:

[{"author":"John","title":"The Book"},{"author":"Smith","title":"Something!"},{"author":"John","title":"The Book"}]

演示: https://3v4l.org/hdJ8H