0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【正規表現】URLの正規表現パターンを作る

Last updated at Posted at 2022-08-08

はじめに

業務にて、よくアクセスするページのURL(全角文字含む)をサクラエディタに追加し、ダブルクォーテーションで囲むことでクリッカブルなテキストにしたく試行錯誤したので備忘録を作成。

内容

ここでいうURLとは、http://~.com/.../...のような形式のものを指す。

URLの正規表現パターン
(?<=")([a-zA-Z]*:\/\/)\S*(?=")

ダブルクォーテーションで囲んだ部分のみをクリッカブルにしたいので、頭と末尾にそれぞれ肯定後読み((?<="))、肯定先読み((?="))のマッチングパターンを追加する。
http://またはhttps://で始まる文字列にマッチさせるよう、([a-zA-Z]*:\/\/)を記載。
そのあとの文字列は全角文字でも許容するよう、非空白文字(\S)の一回以上の繰り返しを採用した。

まとめ

おわり。正規表現がもっと使えるようになりたい。特に(肯|否)定(先|後)読み。

0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?