メインコンテンツ

whitespacePattern

説明

pat = whitespacePattern は、スペースやタブなど、1 つ以上の空白文字から成るテキストに一致するパターンを作成します。

pat = whitespacePattern(N) は、ちょうど N 個の空白文字から成るテキストに一致します。

pat = whitespacePattern(minCharacters,maxCharacters) は、minCharacters 個以上、maxCharacters 個以下の空白文字から成るテキストに一致します。inf は、maxCharacters に対応する有効な値です。whitespacePattern"最長一致" であり、maxCharacters にできるだけ近い数の空白文字に一致します。

すべて折りたたむ

whitespacePattern を使用して、char(160) のような非標準の空白文字に一致させます。

それぞれがタブと newline 文字を含む異なる空白文字を含む、文字ベクトルの cell 配列を作成します。

whitespaces = {' ' char(9) newline char(32) char(160)}
whitespaces = 1×5 cell
    {' '}    {'→'}    {'↵'}    {' '}    {' '}

whitespacePattern を使用して、空白文字に一致するパターンを作成します。contains を使用して、有効な空白文字を含む文字ベクトルを特定します。

pat = whitespacePattern;
contains(whitespaces,pat)
ans = 1×5 logical array

   1   1   1   1   1

whitespacePattern を使用して、非標準の空白を標準の ' ' 文字に置き換えます。

txt を文字ベクトルとして作成します。

txt = ['This' char(9) 'char' newline 'vector' char(160) 'has' char(32) 'nonstandard' char(8193) 'spaces']
txt = 
    'This	char
     vector has nonstandard spaces'

whitespacePattern を使用して、pat を個別の空白文字に一致する pattern オブジェクトとして作成します。一致したテキストの部分を 1 つのスペースに置き換えます。

pat = whitespacePattern(1);
txt = replace(txt,pat," ")
txt = 
'This char vector has nonstandard spaces'

whitespacePattern を使用して、複数の空白文字が存在する場合に間隔を修正します。

txt を string として作成します。whitespacePattern を使用して、pat を 2 つ以上の空白文字に一致する pattern オブジェクトとして作成します。一致したテキストの部分を 1 つのスペースに置き換えます。

txt = "Text looks   strange    with    extra    spaces";
pat = whitespacePattern(2,inf);
txt = replace(txt,pat," ")
txt = 
"Text looks strange with extra spaces"

入力引数

すべて折りたたむ

一致する文字数。非負の整数スカラーとして指定します。

データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

一致する最小文字数。非負の整数スカラーとして指定します。

データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

一致する最大文字数。非負の整数スカラーとして指定します。

データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

出力引数

すべて折りたたむ

パターン式。patternオブジェクトとして返されます。

詳細

すべて折りたたむ

拡張機能

すべて展開する

スレッドベースの環境
MATLAB® の backgroundPool を使用してバックグラウンドでコードを実行するか、Parallel Computing Toolbox™ の ThreadPool を使用してコードを高速化します。

バージョン履歴

R2020b で導入