Main Content

lineBoundary

行頭または行末に一致

R2020b 以降

説明

pat = lineBoundary は、行頭または行末 (newline 文字を含む) に一致するパターンを作成します。lineBoundary は、~ 演算子を使用して否定できます。否定した場合、~lineBoundary は、2 つの文字がいずれも newline 文字でない限り、任意の 2 つの文字に一致します。

pat = lineBoundary(type) は、行頭と行末のどちらに一致させるかを指定します。type は、'start''end''either' (既定値) のいずれかです。

すべて折りたたむ

lineBoundary を使用して、1 行のテキストの先頭または末尾に一致させます。

newline 文字を含む string を作成します。改行の直後にある文字に一致するパターンを作成します。

txt = "This is line one." + newline + "Here is line two.";
pat = lineBoundary + lettersPattern;

パターンを抽出します。

firstWord = extract(txt,pat)
firstWord = 2x1 string
    "This"
    "Here"

lineBoundary"start" オプションを使用して、行の指定した終点に一致させます。

newline 文字を含む string を作成します。2 つの "start" 行境界の間にある任意の文字に一致するパターンを作成します。

txt = "This is line one." + newline + "Here is line two." + newline + "Last but not least.";
pat = lineBoundary("start") + wildcardPattern(1,inf) + lineBoundary("start");

パターンを抽出します。

extract(txt,pat)
ans = 2x1 string
    "This is line one...."
    "Here is line two...."

~ 演算子を使用して、lineBoundary を否定します。これは、2 つの文字がどちらも newline 文字でない場合に、その 2 つの文字間の境界に一致します。

newline 文字を含む string を作成します。1 行のテキストの先頭でも末尾でもない文字に一致するパターンを作成します。

txt = "This is line one" + newline + "Here is line two";
pat = ~lineBoundary + lettersPattern + ~lineBoundary;

パターンを抽出します。

firstWord = extract(txt,pat)
firstWord = 8x1 string
    "his"
    "is"
    "line"
    "on"
    "ere"
    "is"
    "line"
    "tw"

入力引数

すべて折りたたむ

境界タイプ。'start''end' または 'either' として指定します。

データ型: char | string

出力引数

すべて折りたたむ

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

拡張機能

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

バージョン履歴

R2020b で導入