LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Sunday, January 28, 2018

正規表現で文章から半角英字(大文字)を抜き出したい /[A-Z]+/g


文字列の中から半角英字(大文字)を取得したくて調べて書いたコードです

今回書いた半角英字(大文字)だけを抜き出す正規表現

/[A-Z]+/g



コード.gs
function get_upper_alphabet(){
  var str = "abcABC123abcABC123かなカナカナ仮名ひらがなカタカナカタカナ漢字";
  var pattern = /[A-Z]+/g;
  var result = str.match(pattern);
  Logger.log(result);
}
意訳
この機能がやること
探索対象の文字列を用意しておく
半角英字(大文字)のパターン
一致するものを探して
ログに出す








参考
Unicode 10.0 Character Code Charts
http://www.unicode.org/charts/

Basic Latin (ASCII)
http://www.unicode.org/charts/PDF/U0000.pdf

Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...