regex php将字符串中的确切单词从不同的组中分离出来

问题描述 投票:5回答:1

我已经尽力了,但是仍然不知道如何解决这个问题:

我有一个字符串ex:

  • "--included-- in selling price: 5 % vat usd 10.00 packaging fees 2 % notifying fees"
  • "--not included-- in selling price: us$ 35.00 express fees 2 % notifying fees"

我想知道税款是“包含”还是“排除”,费用是“%”还是“货币”问题是,它与附加到税名“ vat usd”的币种同时未检测到货币“ usd”]

我如何在不同的组中将货币与纳税人的名称分开。

我在这里做了

(--excluded--|--included--|--not included--)([a-z ]*)?:?(usd | aed | mad | € | us\$ )?([ \. 0-9 ]*)(%)?([a-z A-z ?]*) (aed|mad|€|us\$)*((aed|mad|€|us\$)+)?([\. 0-9 ]*)(%)?([a-z A-z]*)(.*)?

这是我得到的

Match 1
Full match  0-83    --included-- in selling price: 5 % vat usd 10.00 packaging fees 2 % notifying fees

Group 1.    0-12    --included--

Group 2.    12-29    in selling price

Group 4.    30-33    5 

Group 5.    33-34   %

Group 6.    34-42    vat usd

Group 10.   43-49   10.00 

Group 12.   49-64   packaging fees 

Group 13.   64-82   2 % notifying fees

这是我想要的

Match 1
Full match  0-83    --included-- in selling price: 5 % vat usd 10.00 packaging fees 2 % notifying fees

Group 1.    0-12    --included--

Group 2.    12-29    in selling price

Group 4.    30-33    5 

Group 5.    33-34   %

Group 6.    34-38    vat

Group 7.    38-42    usd

Group 10.   43-49   10.00 

Group 12.   49-64   packaging fees 

Group 13.   64-82   2 % notifying fees

我尽我所能,但仍然想不出办法解决这个问题:我有一个字符串,例如:“-包括-售价:5%增值税10.00美元的包装费2%的通知费” --not ...

php regex word
1个回答
2
投票

这里是解决方法:

© www.soinside.com 2019 - 2024. All rights reserved.