LoginSignup
1
1

勉強メモ26_サクラエディタの文字列置換で正規表現を利用するときのメモ(つどつど更新記事)

Last updated at Posted at 2021-08-09

0 はじめに

  • サクラエディタで何かのファイルを開いて、
    正規表現を使って文字を置換する場合の色々なメモです。

パターン1 空行を削除する

  • ①置換前の内容

image.png

  • ②置換処理
    • 置換前:^[\r\n]+
    • 置換後:
       image.png
  • ③置換後の内容

image.png

パターン2 文字列を複数検索

  • ①検索前の内容

image.png

  • ②検索処理
    • 検索条件:あああああ|おおおおお
      image.png
  • ③検索後の結果

image.png

パターン3 VBAのソースの中で空行、改行、コメントアウト以外を取得

  • ①検索前の内容

image.png

  • ②検索処理
    • 検索条件:^(?!.*'|[\r\n+]).+$
      image.png
  • ③検索後の結果

image.png

パターン4 VBAのソースの中でコメントアウト行を取得

  • ①検索前の内容

image.png

  • ②検索処理
    • 検索条件:.*'
      image.png
  • ③検索後の結果

image.png

パターン5 Grepの正規表現

  • ①検索するディレクトリー

image.png

  • ②テキストファイルの中身
common2015-10-05-11-44.log
test

aaaa


test
common2015-11-22-10-34.log
errerwrwe

test


fsdfafa
common2015-12-01-11-44 .log
rrrrr


dfsfsdfasftest


test


sadfadfadfatestfgsfgsgsdg
  • ③Grep検索方法
    • パターン1 ファイル項目を空白区切りで検索

    • ファイル:common2015-10*.log common2015-11*.log common2015-12*.log
      image.png

    • パターン2 ファイル項目で正規表現は使えない

    • ファイル:common2015-(10|11|12)-(05|22|11).*log
      image.png

④Grep検索結果
パターン1
検索条件  "test"
検索対象   common2015-10*.log common2015-11*.log common2015-12*.log
フォルダ   C:\kaihatsu\02_sakuraEditor\grep
    (サブフォルダも検索)
    (英大文字小文字を区別しない)
    (正規表現:bregonig.dll Ver.3.06 with Onigmo 5.15.0)
    (文字コードセットの自動判別)
    (一致した行を出力)


C:\kaihatsu\02_sakuraEditor\grep\common2015-10-05-11-44.log(1,1)  [SJIS]: test
C:\kaihatsu\02_sakuraEditor\grep\common2015-10-05-11-44.log(6,1)  [SJIS]: test
C:\kaihatsu\02_sakuraEditor\grep\common2015-11-22-10-34.log(3,1)  [SJIS]: test
C:\kaihatsu\02_sakuraEditor\grep\common2015-12-01-11-44 .log(4,11)  [SJIS]: dfsfsdfasftest
C:\kaihatsu\02_sakuraEditor\grep\common2015-12-01-11-44 .log(7,1)  [SJIS]: test
C:\kaihatsu\02_sakuraEditor\grep\common2015-12-01-11-44 .log(10,12)  [SJIS]: sadfadfadfatestfgsfgsgsdg
6 個が検索されました。
パターン2
検索条件  "test"
検索対象   common2015-(10|11|12)-(05|22|11).*log
フォルダ   C:\kaihatsu\02_sakuraEditor\grep
    (サブフォルダも検索)
    (英大文字小文字を区別しない)
    (正規表現:bregonig.dll Ver.3.06 with Onigmo 5.15.0)
    (文字コードセットの自動判別)
    (一致した行を出力)
0 個が検索されました。

パターン6 番号から始まる文の前に★を挿入する

  • ①置換前の内容

image.png

  • ②置換処理
    • 置換前:(^[0-9].*)
    • 置換後:★$1
      image.png
  • ③置換後の内容

image.png

パターン7 HTMLタグで囲まれた文字の部分だけ取得

^\s*
< .* >\r\n \r\n
^\s*(\r\n|\r|\n)

パターン8 先頭が#1、#2、#10、#11とかなっているところを# 1、# 2、# 3、# 10、みたいに#と数字の中に半角スペースを挿入する

  • ①置換前の内容
    image.png

  • ②置換処理
    • 置換前:^#(\d{1,2})
    • 置換後:# $1
      image.png
  • ③置換後の内容

image.png

パターン9 年号Y年MM年DD日を検索する方法

  • 検索前の内容
    image.png

  • 検索内容

    • 条件:(\D+)(\d+)年(\d+)月(\d+)日
      image.png
  • 検索後の結果
    image.png

1
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
1
1