0
1

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 5 years have passed since last update.

正規表現を使った文字列処理

Last updated at Posted at 2018-06-23

文字列の判定

RegexクラスのIsMatchメソッドを使う。

文字列の検索

最初の部分文字列を見つける

RegexクラスのMatchメソッドを使う。

一致する文字列をすべて見つける

RegexクラスのMatchesメソッドを使う。

文字列の置換と分割

置換

RegexクラスのReplaceメソッドを使う。

分割

RegexクラスのSplitメソッドを使う。

グループ化

"()"でグループ化する。インデックスは、1スタート。
Groupsプロパティで文字列を取り出すことができる。

最長一致の原則

  • 半角英数字 [0-9a-zA-Z]
  • 平成(\d+)年
  • 数値 ^[-+]?(\d+)(.\d+)?$
  • 携帯の電話番号 ^0[789]0-\d{4}-\d{4}$
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?