説明
[0-9]+(?:\.[0-9]+)?\s*(?:%|percent)|\$(?:[0-9]{3},)*[0-9]+(?:\s(?:thousand|million|billion|trillion))?
この正規表現は、次の操作を行います:
- を
- 数が続いてもよいし、小数点なし、パーセントを表す全ての数字を見つけます
%
記号またはリテラルワード
- ドルが主要なドル記号
- で
- を金額であり、すべての数字がカンマ区切り
- は、千、百万、億、または兆
のような言葉が続くことがあり挙げられる見つけます
- 避け、他の非ドルまたはパーセント数字
例
ライブデモ
https://regex101.com/r/uG6mQ4/1
サンプルテキスト
「100%の価格セグメント間の選択は低かったものの、トップエンドの家の関心は高いままと355個の特性、または全家屋の37.6%が873,599ドルと1百万ドルを超える価格を引きつけました。
サンプル
[0][0] = 100%
[1][0] = 37.6 percent
[2][0] = $873,599
[3][0] = $1 million
説明
NODE EXPLANATION
----------------------------------------------------------------------
[0-9]+ any character of: '0' to '9' (1 or more
times (matching the most amount possible))
----------------------------------------------------------------------
(?: group, but do not capture (optional
(matching the most amount possible)):
----------------------------------------------------------------------
\. '.'
----------------------------------------------------------------------
[0-9]+ any character of: '0' to '9' (1 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
)? end of grouping
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
% '%'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
percent 'percent'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
\$ '$'
----------------------------------------------------------------------
(?: group, but do not capture (0 or more times
(matching the most amount possible)):
----------------------------------------------------------------------
[0-9]{3} any character of: '0' to '9' (3 times)
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
[0-9]+ any character of: '0' to '9' (1 or more
times (matching the most amount possible))
----------------------------------------------------------------------
(?: group, but do not capture (optional
(matching the most amount possible)):
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
thousand 'thousand'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
million 'million'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
billion 'billion'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
trillion 'trillion'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
)? end of grouping
----------------------------------------------------------------------
を照合し、最小限の自己完結型の再現性のある方法で、あなたの最高の試みのためのRコードを入力してください。質問する方法の詳細については、[mcve]を参照してください。 –
あなたは新しいポスターです。あなたがStackOverflow(SO)をコード作成サービスと考えるような、データとコードがなく、質問が聞こえるからです。これらのSOのガイドライン[こちら](http://stackoverflow.com/help/mcve)を見ることができます。また、正規表現のチュートリアルを読むのが役に立つかもしれないと聞こえます。私は学習しているときに、[これは](http://www.rexegg.com/)が役立つことがわかりました。 StackOverflowの期待通りに閉じられていない場合は、質問を再編集することを歓迎します。 –