给定这样的字符串,我想创建一个捕获字符串“Identificador”的正则表达式。此字符串已本地化,因此存在问题。
作为提示,我认为可以轻松检索它,因为它就是“------------”之后的字符串。每个条目由“-------”分隔,第一个元素是我想要的字符串。因此,正则表达式可以返回“Identificador”或一系列{“Identificador”,“Identificador”,“Identificador”,...}(每个条目一个字符串)。
以下是示例输入:
Administrador de arranque de firmware
-----------------------------------
Identificador {fwbootmgr}
displayorder {bootmgr}
Administrador de arranque de Windows
----------------------------------
Identificador {bootmgr}
device partition=G:
path \efi\boot\bootarm.efi
description Windows Boot Manager
locale en-US
inherit {globalsettings}
booterrorux Simple
default {default}
displayorder {838bb5a3-712f-11e8-b4ea-001a7dda710e}
{default}
{7619dcc9-fafe-11d9-b411-000476eba25f}
bootsequence {01de5a27-8705-40db-bad6-96fa5187d4a6}
timeout 30
displaybootmenu Yes
processcustomactionsfirstYes
persistbootsequence Yes
Cargador de arranque de Windows
-----------------------------
Identificador {311b88b5-9b30-491d-bad9-167ca3e2d417}
device ramdisk=[F:]\PROGRAMS\UpdateOS\UpdateOS.wim,{ramdiskoptions}
path \windows\system32\boot\winload.efi
description Windows Update OS (Boot from WIM)
inherit {bootloadersettings}
osdevice ramdisk=[F:]\PROGRAMS\UpdateOS\UpdateOS.wim,{ramdiskoptions}
systemroot \windows
bootmenupolicy Standard
winpe Yes
Cargador de arranque de Windows
-----------------------------
Identificador {7619dcc9-fafe-11d9-b411-000476eba25f}
device partition=F:
path \windows\system32\boot\winload.efi
description Windows Phone
locale en-US
inherit {bootloadersettings}
bootdebug No
nointegritychecks Yes
osdevice partition=F:
systemroot \windows
bootmenupolicy Standard
bootstatuspolicy IgnoreAllFailures
ems No
Aplicaci¢n de arranque de Windows (1020000a)
------------------------------------------
Identificador {01de5a27-8705-40db-bad6-96fa5187d4a6}
device partition=G:
path \windows\system32\boot\mobilestartup.efi
description Mobile Startup App
inherit {bootloadersettings}
recoverysequence {311b88b5-9b30-491d-bad9-167ca3e2d417}
recoveryenabled Yes
nointegritychecks Yes
Aplicaci¢n de arranque de Windows (1020000a)
------------------------------------------
Identificador {0ff5f24a-3785-4aeb-b8fe-4226215b88c4}
device partition=G:
path \windows\system32\boot\ffuloader.efi
description FFU Loader (User Invoked)
inherit {bootloadersettings}
custom:26000201 Yes
Aplicaci¢n de arranque de Windows (1020000a)
------------------------------------------
Identificador {default}
device partition=G:
path \EFI\boot\BootShim.efi
description BootShim
nointegritychecks Yes
testsigning Yes
Aplicaci¢n de arranque de Windows (1020000a)
------------------------------------------
Identificador {838bb5a3-712f-11e8-b4ea-001a7dda710e}
device partition=G:
path \Windows\System32\BOOT\developermenu.efi
description Developer Menu
Aplicaci¢n de arranque de Windows (1020000a)
------------------------------------------
Identificador {bd8951c4-eabd-4c6f-aafb-4ddb4eb0469b}
device partition=G:
path \windows\system32\boot\resetphone.efi
description Reset My Phone Application
inherit {bootloadersettings}
custom:26000206 Yes
Configuraci¢n de EMS
--------------------
Identificador {emssettings}
bootems No
Configuraci¢n del depurador
---------------------------
Identificador {dbgsettings}
description Windows Debugger Settings
Configuraci¢n global
--------------------
Identificador {globalsettings}
inherit {dbgsettings}
{emssettings}
bootuxtransitiontime 5000
booterrorux Simple
extendedinput Yes
nobootuxtext Yes
nobootuxprogress Yes
nobootuxfade No
nokeyboard Yes
mobilegraphics Yes
custom:250000e0 1
chargethreshold 255
custom:25000511 90
bootflow 0x0
offmodecharging No
Configuraci¢n del cargador de arranque
------------------------------------
Identificador {bootloadersettings}
inherit {globalsettings}
advancedoptions No
optionsedit No
Opciones del disco RAM de configuraci¢n
-------------------------------------
Identificador {ramdiskoptions}
description Ramdisk Options
ramdisksdidevice partition=G:
ramdisksdipath \boot\boot.sdi
答案 0 :(得分:2)
您可以使用正面的lookbehind (?<=
断言左侧的一个或多个连字符-+
后跟一个或多个空格字符\s+
,然后匹配一次或多次不是空格字符\S+
或者从行的开头^
匹配一个或多个连字符-+
,后跟一个或多个空格字符\s+
并在一个组中捕获(您的值在第1组中) )一次或多次不是空格\S+
。
答案 1 :(得分:1)
也许这就像在“ - ”和空白处使用lookbehind一样简单。
(?<=-\s)(\w*)
直播正则表达式here。 这假设其他地方没有其他尾随连字符。
对于.NET使用:
(?<=-\s+)(\w*)
答案 2 :(得分:0)