在Vim中或其他地方使用正则表达式搜索 [英] Searching using regex in Vim or elsewhere

查看:191
本文介绍了在Vim中或其他地方使用正则表达式搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方式来寻找一系列的十六进制数字的文本再presentation。我在一个二进制文件的十六进制转储检索。

I'm looking for a way to search for the text representation of a series of hexadecimal numbers. I search in the hex dump of a binary file.

0x000001A0: 36 5B 09 76 99 31 55 09 78 99 34 51 49 BF E0 03
0x000001B0: 28 0B 0A 03 0B E0 07 28 0B 0A 03 0B 49 58 09 35

的问题是,该图案可以在滚动到下一行。例如,在上述两行,我不能够立即搜索 03 28 0B ,因为它是两行。

我已经从最近发帖称正则表达式是要走的路告诉记者,但我不熟悉它,不知道该用什么:记事本+ +,Vim的,Word或其他任何东西。

I have been told from recent posting that regex is the way to go, but I'm unfamiliar with it and do not know what to use: Notepad++, Vim, Word or anything else.

修改1 ,显示上面的文本文件是从一个二进制文件导出,我可以用记事本+ +。

EDIT 1 The text file that shows the above was derived from a binary file and I can use Notepad++.

编辑2 例如目的,说我试图让尽可能接近11点45分00秒(军用时间)成为可能。 03 28 0B 0A 03 0B 散落在上面的两行,可以理解为3秒,40分钟,2011年3月10日11天时间。我期待通过这个文件中查找,看我怎么能接近到11点45分零零秒。

EDIT 2 For example purposes, say I'm trying to get as close to 11:45:00 (military time) as possible. 03 28 0B 0A 03 0B scattered over the two lines above, can be read as "3 seconds, 40 minutes, 11 hours on the 10th day of March 2011". I'm looking to go through this file looking to see how close I can get to 11:45:00.

推荐答案

让我提出以下的映射关系采取一些十六进制数字,从
用户输入或可视选择,创造合适的模式和运行搜索
吧。

Let me propose the following mappings that take a number of hex digits from user input or visual selection, create appropriate pattern and run search for it.

nnoremap <silent> <expr> <leader>x/ SearchHexBytes('/', 0)
nnoremap <silent> <expr> <leader>x? SearchHexBytes('?', 0)
vnoremap <silent> <leader>x/ :call SearchHexBytes('/', 1)<cr>/<cr>
vnoremap <silent> <leader>x? :call SearchHexBytes('?', 1)<cr>?<cr>
function! SearchHexBytes(dir, vis)
    if a:vis
        let [qr, qt] = [getreg('"'), getregtype('"')]
        norm! gvy
        let s = @"
        call setreg('"', qr, qt)
    else
        call inputsave()
        let s = input(a:dir)
        call inputrestore()
    endif
    if s =~ "[^ \t0-9A-Fa-f]"
        echohl Error | echomsg 'Invalid hex digits' | echohl None
        return
    endif
    let @/ = join(split(s, '\s\+'), '\%(\s*\|\n0x\x\+:\s*\)')
    return a:dir . "\r"
endfunction

这篇关于在Vim中或其他地方使用正则表达式搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆