出力内容に対してRegExpを使用したら謎の結果になって、タイトルの件について確認したら違いがあることが分かりました。
console.logで表示
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const 対象ファイル = Deno.args[0] | |
const p = Deno.run({cmd:['deno', 'info', 対象ファイル], stdout:'piped'}) | |
const uint = await p.output() | |
const decoder = new TextDecoder("utf-8") | |
const str = decoder.decode(uint) | |
console.log(str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deno run --allow-run --allow-net console.log |
URLだけを取得したいのにうまくマッチしない
console.logで表示した結果が上記の通りなので /[\w\d\.@\/]+/ でマッチすると考えて以下のようにしてみました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const 対象ファイル = Deno.args[0] | |
const p = Deno.run({cmd:['deno', 'info', 対象ファイル], stdout:'piped'}) | |
const uint = await p.output() | |
const decoder = new TextDecoder("utf-8") | |
const str = decoder.decode(uint) | |
const arr = str.split('\n') | |
const re = /[\w\d\.@\/]+/ | |
for(const 行 of arr){ | |
console.log(行 + ' > ' + 行.match(re)) | |
} |
どこにも「0m」なんて表示されていないのに…と思って正規表現の内容を変えながら何度か試してみましたが、どうしてもイメージ通りの結果になりませんでした。
テキストファイルとして出力
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deno info ts2js.ts > stdout.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[0m[1mlocal:[0m C:\deno\1.11.0\ts2js.ts | |
[0m[1mtype:[0m TypeScript | |
[0m[1mdependencies:[0m 11 unique [0m[38;5;8m(total 65.9KB)[0m | |
file:///C:/deno/1.11.0/ts2js.ts [0m[38;5;8m(1.04KB)[0m | |
[0m[38;5;8m└─┬[0m https://deno.land/std@0.97.0/path/mod.ts[0m[38;5;8m (725B)[0m | |
[0m[38;5;8m ├──[0m https://deno.land/std@0.97.0/_util/os.ts[0m[38;5;8m (456B)[0m | |
[0m[38;5;8m ├──[0m https://deno.land/std@0.97.0/path/_interface.ts[0m[38;5;8m (728B)[0m | |
[0m[38;5;8m ├─┬[0m https://deno.land/std@0.97.0/path/common.ts[0m[38;5;8m (1.14KB)[0m | |
[0m[38;5;8m │ └─┬[0m https://deno.land/std@0.97.0/path/separator.ts[0m[38;5;8m (259B)[0m | |
[0m[38;5;8m │ └──[0m [0m[38;5;8mhttps://deno.land/std@0.97.0/_util/os.ts[0m[0m[38;5;8m *[0m | |
[0m[38;5;8m ├─┬[0m https://deno.land/std@0.97.0/path/glob.ts[0m[38;5;8m (12.28KB)[0m | |
[0m[38;5;8m │ ├──[0m [0m[38;5;8mhttps://deno.land/std@0.97.0/_util/os.ts[0m[0m[38;5;8m *[0m | |
[0m[38;5;8m │ ├─┬[0m https://deno.land/std@0.97.0/path/posix.ts[0m[38;5;8m (14.28KB)[0m | |
[0m[38;5;8m │ │ ├──[0m https://deno.land/std@0.97.0/path/_constants.ts[0m[38;5;8m (1.9KB)[0m | |
[0m[38;5;8m │ │ ├──[0m [0m[3m[38;5;8mhttps://deno.land/std@0.97.0/path/_interface.ts[0m[0m[38;5;8m *[0m | |
[0m[38;5;8m │ │ └─┬[0m https://deno.land/std@0.97.0/path/_util.ts[0m[38;5;8m (3.62KB)[0m | |
[0m[38;5;8m │ │ ├──[0m [0m[38;5;8mhttps://deno.land/std@0.97.0/path/_constants.ts[0m[0m[38;5;8m *[0m | |
[0m[38;5;8m │ │ └──[0m [0m[3m[38;5;8mhttps://deno.land/std@0.97.0/path/_interface.ts[0m[0m[38;5;8m *[0m | |
[0m[38;5;8m │ ├──[0m [0m[38;5;8mhttps://deno.land/std@0.97.0/path/separator.ts[0m[0m[38;5;8m *[0m | |
[0m[38;5;8m │ └─┬[0m https://deno.land/std@0.97.0/path/win32.ts[0m[38;5;8m (29.13KB)[0m | |
[0m[38;5;8m │ ├──[0m https://deno.land/std@0.97.0/_util/assert.ts[0m[38;5;8m (405B)[0m | |
[0m[38;5;8m │ ├──[0m [0m[38;5;8mhttps://deno.land/std@0.97.0/path/_constants.ts[0m[0m[38;5;8m *[0m | |
[0m[38;5;8m │ ├──[0m [0m[3m[38;5;8mhttps://deno.land/std@0.97.0/path/_interface.ts[0m[0m[38;5;8m *[0m | |
[0m[38;5;8m │ └──[0m [0m[38;5;8mhttps://deno.land/std@0.97.0/path/_util.ts[0m[0m[38;5;8m *[0m | |
[0m[38;5;8m ├──[0m [0m[38;5;8mhttps://deno.land/std@0.97.0/path/posix.ts[0m[0m[38;5;8m *[0m | |
[0m[38;5;8m ├──[0m [0m[38;5;8mhttps://deno.land/std@0.97.0/path/separator.ts[0m[0m[38;5;8m *[0m | |
[0m[38;5;8m └──[0m [0m[38;5;8mhttps://deno.land/std@0.97.0/path/win32.ts[0m[0m[38;5;8m *[0m |
なぜRegExpがうまくマッチしなかったのかは分かりましたが、テキストファイルとして出力した場合のみ可視化される文字の意味は分かりませんでした…。
0 件のコメント:
コメントを投稿