LoginSignup
8
13

More than 1 year has passed since last update.

'foo@example.com'.match(/\x{email}/)

Last updated at Posted at 2022-08-15

文字クラス拡張すると車輪の再発明防げるかなと思い拡張してみました。

npm version

使い方

メールアドレス

'foo@example.com'.match(/\x{email}/g)
// ['foo@example.com']

URL

'https://example.com/foo/bar'.match(/\x{url}/g)
// ['https://example.com/foo/bar']

都道府県

'島根県にパソコンなんてあるわけないじゃん'.match(/\x{都道府県}/g)
// ['島根県']

IPアドレス

'127.0.0.1'.match(/\x{ip}/g)
// ['127.0.0.1']

FQDN

'example.com sub.example.com'.match(/\x{fqdn}/g)
// ['example.com', 'sub.example.com']

場所

const str = '時どき私はそんな路を歩きながら、ふと、そこが京都ではなくて京都から何百里も離れた仙台とか長崎とか――そのような市へ今自分が来ているのだ――という錯覚を起こそうと努める。'
await str.matchAsync(/\x{場所}/g)
// ['京都', '京都', '仙台', '長崎']

人物

await '昨日、ジョンと山田太郎は松のやでカツ丼を食した。'.matchAsync(/\x{人物}/g)
// ['ジョン', '山田太郎']

インストール

npm install cc-regex

ブラウザ

<script src="https://github30.github.io/cc-regex/index.js">
8
13
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
8
13