LoginSignup
0
0

More than 5 years have passed since last update.

[正規表現] デリミタのエスケープに対応する

Posted at

vCardのように;で区切られたデータの中にエスケープされた\;が入る場合、

wrong.pl
my @sp = split /;/, $value;

などとすると不用意なところで文字列が分割される問題について対応した。

right.pl
my @sp = split /(?<!\\);/, $value;

(?<!エスケープ文字)デリミタ←こういうのを正規表現の拡張構文「後方一致検索の否定形」というらしい。

例によって、言語に依存せず使えるかどうかはわからない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0