查看: 875|回复: 4
打印 上一主题 下一主题

[求助] 正则表达式求助---释义和例句对应显示并加序号

[复制链接]

该用户从未签到

43

主题

448

回帖

3793

积分

贡士

Rank: 6Rank: 6

积分
3793

灌水大神章小蜜蜂章笑傲江湖章

跳转到指定楼层
1
发表于 2015-11-8 10:06:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zhlpen 于 2015-11-8 10:15 编辑

请看下面词条,词典里面释义是一行,例句自上而下排列,当词义很多时,看起来非常凌乱。
请问如何用正则表达式在所有的释义前面
1.自动添加序号;
2.把例句对应到相应的释义下。
看起来很复杂,实际只完成2个功能,对于专家,也许用到的就是几行代码,也许早就有人完成过此项工资,希望不吝指教,让大家受益,在此谢过。

要考虑到有的释义下面可能没有例句
因为有的释义条很多,所以特意取了一个释义多的词来作为例子

</>
abandonar
<span style='font-size:125%'>abandonar</span><br><hr><i> (v.)</i><i> = </i><span style='font-size:115%'>abandon ; abort ; drop ; eschew ; give up ; quit ; quit + Lugar ; relinquish ; stop ; leave + wandering in ; forsake ; sweep aside ; desert ; opt out (of/from) ; scrap ; pull back ; ditch ; surrender ; bail out ; bargain away ; dump ; maroon ; flake out ; leave by + the wayside ; get away (from) ; desist ; go + cold turkey ; walk out on ; walk out ; jump + ship ; junk ; drop by + the wayside</span>.<br> Ex: <i>The Library of Congress has now reconsidered the position, and <b>abandoned</b> what was known as its compatible headings policy</i>.<br> Ex: <i>It is important to know what police or fire responses are triggered by alarms and how that reaction can be <b>aborted</b> and the alarm silenced</i>.<br> Ex: <i>Unfruitful lines of enquiry are <b>dropped</b> and new and more promising search terms are introduced as the search progresses</i>.<br> Ex: <i>However, most contributors to the debate about the future of SLIS have <b>eschewed</b> practicalities in favour of sweeping and dramatic generalizations</i>.<br> Ex: <i>If support for quality cataloging is not going to be given, I think we should <b>give it up</b> entirely</i>.<br> Ex: <i>If you decide not to send or save the message, replace the question mark in front of '<b>Quit</b>' with another character</i>.<br> Ex: <i>She rose, took his hand, wished him well, and <b>quitted the room</b></i>.<br> Ex: <i>The Library will consider <b>relinquishing</b> them only when there is strong assurance that their transfer would not adversely affect the library community</i>.<br> Ex: <i>Program function key 1 (FP1) tells DOBIS/LIBIS to <b>stop</b> whatever it is doing and go back to the function selection screen</i>.<br> Ex: <i>It is our professional duty to help the reader, leading him from author to author, book to book, with enough sure-footed confidence that he is guided up the literary mountain and not <b>left wandering in</b> the viewless foothills because of one's own incompetence</i>.<br> Ex: <i>Indeed, she was delighted to <b>forsake</b> the urban reality of steel and glass, traffic and crime, aspirin and litter, for the sort of over-the-fence friendliness of the smaller city</i>.<br> Ex: <i>The development of optical fibres for information transmission has exciting potential here, but there is a very large investment in the present systems which cannot be <b>swept aside</b> overnight</i>.<br> Ex: <i>Recently, however, libraries have <b>deserted</b> the individual and have pandered too much to the needs of the general public</i>.<br> Ex: <i>The author takes a critical look at the UK government's education policy with regard to schools' '<b>opting out' of</b> local government control</i>.<br> Ex: <i>There have even been rumours of plans to <b>scrap</b> most of the industrial side of its work and disperse key elements, such as the work on regional and industrial aid, to the provinces</i>.<br> Ex: <i>To <b>pull back</b> now would make both her and him look bad</i>.<br> Ex: <i>It is time that higher education institutions accepted the wisdom of collaboration and <b>ditched</b>, once and for all, the rhetoric of competition</i> = <i>Ya es hora de que las instituciones de ense&#241;anza superior acepten la colaboración y <b>rechacen</b>, de una vez por todas, la competitividad</i>.<br> Ex: <i>Instead the two ecclesiastical disputes which arose from Diocletian's decree to <b>surrender</b> scriptures must be seen as more disastrous to Christian unity than the destruction of libraries</i>.<br> Ex: <i>In the article '<b>Bailing out</b>' 9 of the 10 librarians interviewed admitted that they were trying to get out of librarianship partly due to unrealistic expectations learned in library school</i>.<br> Ex: <i>Reduced support is a fact of life, and librarians cannot <b>bargain away</b> their budget pressures</i>.<br> Ex: <i>The books may simply be laid before the librarian as they are found, '<b>dumped</b> in his lap', as one writer puts it</i>.<br> Ex: <i>A seemingly simple tale of schoolboys <b>marooned</b> on an island, the novel 'Lord of the Flies' is an enigmatic and provocative piece of literature</i>.<br> Ex: <i>The actress <b>flaked out</b> again and the director is trying to line up a replacement</i>.<br> Ex: <i>She seeks to recontextualize those events that history has estranged, destroyed or capriciously <b>left by the wayside</b></i>.<br> Ex: <i>Guards in the lead car of the convoy threw their doors open and ran for cover, screaming, '<b>Get away, get away</b>'</i>.<br> Ex: <i>One of them sputtered and gesticulated with sufficient violence to induce us to <b>desist</b></i>.<br> Ex: <i>Judging by the critical responses to the article so far, it looks like the world isn't quite ready to <b>go cold turkey</b> on its religion addiction</i>.<br> Ex: <i>There are many thankless jobs in this world, but does that mean you can just <b>walk out on</b> them for your own selfish reasons?</i>.<br> Ex: <i>At least five members of the audience <b>walked out</b> during the bishop's address</i>.<br> Ex: <i>A new study suggests that up to 40% of currently employed individuals are ready to <b>jump ship</b> once the economy rebounds</i>.<br> Ex: <i>I had a motherboard with a lot of bad capacitors so I decided to <b>junk</b> it instead of repairing</i>.<br> Ex: <i>He was one of the few workers who saw the project out to the very end when some had <b>dropped by the wayside</b></i>.
</>


把此词条调整后显示为如下效果


(v.)
1.abandon
Ex: The Library of Congress has now reconsidered the position, and abandoned what was known as its compatible headings policy.
2.abort
Ex: It is important to know what police or fire responses are triggered by alarms and how that reaction can be aborted and the alarm silenced.
3.drop
Ex: Unfruitful lines of enquiry are dropped and new and more promising search terms are introduced as the search progresses.
4.eschew
Ex: However, most contributors to the debate about the future of SLIS have eschewed practicalities in favour of sweeping and dramatic generalizations.
5.give up
Ex: If support for quality cataloging is not going to be given, I think we should give it up entirely.
6.quit
Ex: If you decide not to send or save the message, replace the question mark in front of 'Quit' with another character.
7.quit + Lugar
Ex: She rose, took his hand, wished him well, and quitted the room.
8.relinquish
Ex: The Library will consider relinquishing them only when there is strong assurance that their transfer would not adversely affect the library community.
9.stop
Ex: Program function key 1 (FP1) tells DOBIS/LIBIS to stop whatever it is doing and go back to the function selection screen.
11.leave + wandering in
Ex: It is our professional duty to help the reader, leading him from author to author, book to book, with enough sure-footed confidence that he is guided up the literary mountain and not left wandering in the viewless foothills because of one's own incompetence.
12.forsake
Ex: Indeed, she was delighted to forsake the urban reality of steel and glass, traffic and crime, aspirin and litter, for the sort of over-the-fence friendliness of the smaller city.
13.sweep aside
Ex: The development of optical fibres for information transmission has exciting potential here, but there is a very large investment in the present systems which cannot be swept aside overnight.
14.desert
Ex: Recently, however, libraries have deserted the individual and have pandered too much to the needs of the general public.
15.opt out (of/from)
Ex: The author takes a critical look at the UK government's education policy with regard to schools' 'opting out' of local government control.
16.scrap
Ex: There have even been rumours of plans to scrap most of the industrial side of its work and disperse key elements, such as the work on regional and industrial aid, to the provinces.
17.pull back
Ex: To pull back now would make both her and him look bad.
18.ditch
Ex: It is time that higher education institutions accepted the wisdom of collaboration and ditched, once and for all, the rhetoric of competition = Ya es hora de que las instituciones de ense&#241;anza superior acepten la colaboración y rechacen, de una vez por todas, la competitividad.
19.surrender
Ex: Instead the two ecclesiastical disputes which arose from Diocletian's decree to surrender scriptures must be seen as more disastrous to Christian unity than the destruction of libraries.
20.bail out
Ex: In the article 'Bailing out' 9 of the 10 librarians interviewed admitted that they were trying to get out of librarianship partly due to unrealistic expectations learned in library school.
21.bargain away
Ex: Reduced support is a fact of life, and librarians cannot bargain away their budget pressures.
22.dump
Ex: The books may simply be laid before the librarian as they are found, 'dumped in his lap', as one writer puts it.
23.maroon
Ex: A seemingly simple tale of schoolboys marooned on an island, the novel 'Lord of the Flies' is an enigmatic and provocative piece of literature.
24.flake out
Ex: The actress flaked out again and the director is trying to line up a replacement.
25.leave by + the wayside
Ex: She seeks to recontextualize those events that history has estranged, destroyed or capriciously left by the wayside.
26.get away (from)
Ex: Guards in the lead car of the convoy threw their doors open and ran for cover, screaming, 'Get away, get away'.
27.desist
Ex: One of them sputtered and gesticulated with sufficient violence to induce us to desist.
28.go + cold turkey
Ex: Judging by the critical responses to the article so far, it looks like the world isn't quite ready to go cold turkey on its religion addiction.
29.walk out on
Ex: There are many thankless jobs in this world, but does that mean you can just walk out on them for your own selfish reasons?.
30.walk out
Ex: At least five members of the audience walked out during the bishop's address.
31.jump + ship
Ex: A new study suggests that up to 40% of currently employed individuals are ready to jump ship once the economy rebounds.
32.junk
Ex: I had a motherboard with a lot of bad capacitors so I decided to junk it instead of repairing.
33.drop by + the wayside
Ex: He was one of the few workers who saw the project out to the very end when some had dropped by the wayside.

该用户从未签到

20

主题

222

回帖

4029

积分

贡士

Rank: 6Rank: 6

积分
4029

灌水大神章小蜜蜂章笑傲江湖章

2
发表于 2015-11-8 10:18:13 | 只看该作者
不可能,辦不到
正則不是萬能的

该用户从未签到

43

主题

448

回帖

3793

积分

贡士

Rank: 6Rank: 6

积分
3793

灌水大神章小蜜蜂章笑傲江湖章

3
 楼主| 发表于 2015-11-8 10:36:49 | 只看该作者
我是办不到,没准有人能办到,我所要的功能不多,只是2个功能,也许不像想象的那么难,如果很容易还用求助吗,希望多提思路。
我是这样想的
第一查找单词">abandon ; "把他分成3部分">" "abandon" " ; ";
再次查找带有Ex:的例句"Ex: The Library of Congress has now reconsidered the position, and " "abandon" "ed what was known as its compatible headings policy"
当然要包含前后的格式字符
然后开始替换,替换33后就完成了释义对应
下一步就是给每个释义前面加序号
我看了好多字典,就是后面一个释义也写着1. 虽然我没有看到原词典,我想原版词典肯定不会这样,2个释义及以上才分序号的。
自己顶起来

该用户从未签到

20

主题

222

回帖

4029

积分

贡士

Rank: 6Rank: 6

积分
4029

灌水大神章小蜜蜂章笑傲江湖章

4
发表于 2015-11-8 11:05:34 | 只看该作者
辦不到就是辦不到,講再多都沒用
隨便兩個例子
例句是give it up要怎麼對應到give up
例句是swept aside要怎麼對應到sweep aside,根本不可能

加序號倒簡單
html <ol> <li> tags

该用户从未签到

43

主题

448

回帖

3793

积分

贡士

Rank: 6Rank: 6

积分
3793

灌水大神章小蜜蜂章笑傲江湖章

5
 楼主| 发表于 2015-11-8 13:49:19 | 只看该作者
等待论坛上的高手吧,耐心等待,说不准哪天就有了结果。

还有加序号说全点,查找  --- 替换---,