我试图通过在Java中创建$RegID = "abracadabra";
$tableName="DefaultDelivery";
$marshaler = new Marshaler();
$requested_delivery = '{"Packet0":{"PacketNo":"2","Quantity":"1000ml","Type":"Toned Milk"},"Packet2":{"PacketNo":"4","Quantity":"250ml","Type":"Toned Milk"}}';
$eav = $marshaler->marshalJson('
{
":RequestedDelivery" : '.$requested_delivery.'
}
');
$key = $marshaler->marshalJson('
{
"RegistrationID" : "'.$RegID.'"
}
');
$params = [
'TableName' => "$tableName",
'Key' => $key,
'ExpressionAttributeValues' => $eav,
'UpdateExpression' => 'SET RequestedDelivery = :RequestedDelivery',
'ReturnValues' => 'UPDATED_NEW'
];
try {
$result = $client->updateItem($params);
echo "SUCCESS";
}
catch (DynamoDbException $e){
echo "Unable to update Item : \n";
}
来拆分文档的行。
WordCount示例中的默认Pattern
是这样的:Pattern
。
然而,这种模式的问题在于它将所有内容分成一个单词,而我想将(我,你,它)这样的东西保存在一起。到目前为止,我尝试的是"\\s*\\b\\s*"
,
问题在于,当我有一个测试字符串时,例如:
[a-zA-Z]+'{0,1}[a-zA-Z]*
并运行
Pattern BOUNDARY = "[a-zA-Z]+'{0,1}[a-zA-Z]*"
String test = "Hello i'm @£$@you @@can !!be.
我没有结果。理想情况下,我想得到
for(String word : BOUNDARY.split(test){
println(word)}
欢迎任何想法。在regex101.com中,我提出的正则表达式就像一个魅力,所以我猜我在Java部分误解了一些东西。
答案 0 :(得分:1)
你的初始模式是在用0+空格模式包围的单词边界处分裂。第二种模式是匹配子串。
像这样使用:
String BOUNDARY_STR = "[a-zA-Z]+(?:'[a-zA-Z]+)?";
String test = "Hello i'm @£$@you @@can !!be.";
Matcher matcher = Pattern.compile(BOUNDARY_STR).matcher(test);
List<String> results = new ArrayList<>();
while (matcher.find()){
results.add(matcher.group(0));
}
System.out.println(results); // => [Hello, i'm, you, can, be]
请参阅Java demo
注意我使用了匹配
的[a-zA-Z]+(?:'[a-zA-Z]+)?
[a-zA-Z]+
- 一个或多个ASCII字母(?:'[a-zA-Z]+)?
- 可选的子字符串
'
- 撇号[a-zA-Z]+
- 一个或多个ASCII字母您也可以使用单词边界包装模式,以仅匹配用非单词字符"\\b[a-zA-Z]+(?:'[a-zA-Z]+)?\\b"
括起来的单词。
要查找所有Unicode字母,请使用"\\p{L}+(?:'\\p{L}+)?"
。