regex-lookarounds

Negative lookbehind in a regex with an optional prefix

送分小仙女□ 提交于 2021-01-27 15:37:25
问题 We are using the following regex to recognize urls (derived from this gist by Jim Gruber). This is being executed in Scala using scala.util.matching which in turn uses java.util.regex : (?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?!js)[a-z]{2,6}/)(?:[^\s()<>{}\[\]]+)(?:[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:(?<!@)[a-z0-9]+(?:[.\-][a-z0-9]+)*[.](?!js)[a-z]{2,6}\b/?(?!@))) This version has escaped forward slashes, for Rubular: (?i)\b(((?:https?:(?:\/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?!js)

Regex to find a multi line string that includes another string between lines

南楼画角 提交于 2021-01-27 08:16:47
问题 my first Q here. I have a log file that has multiple similar strings as hits: Region: AR OnlineID: Atl_Tuc ---Start--- FIFA 18 Legacy Edition ---END--- Region: FR OnlineID: jubtrrzz ---Start--- FIFA 19 Undertale Pro Evolution Soccer™ 2018 ---END--- Region: US OnlineID: Cu128yi ---Start--- KINGDOM HEARTS HD 1.5 +2.5 ReMIX ---END--- Region: RO OnlineID: Se116 ---Start--- Real Farm EA SPORTS™ FIFA 20 LittleBigPlanet™ 3 ---END--- Region: US OnlineID: CAJ5Y ---Start--- Madden NFL 18: G.O.A.T.

Extract value from a list of key-value pairs using grep

故事扮演 提交于 2020-12-26 11:00:59
问题 I have a string containing a list of key-value pairs like this: "a:1,b:2,c:3". I would like to extract a value for a specified key so that e.g. I would get "1" for "a". I was planning to do it with a regex like this: '(?<=(^|,)$KEY:)^,*' but it seems grep doesn't support lookarounds. (I'm not even sure this regex works correctly.) Is there another way? 回答1: You may use grep -oP "(?:^|,)$KEY:\K[^,]+" The -o option outputs matches. -P enables PCRE engine. The double quotes are necessary for

Extract value from a list of key-value pairs using grep

不羁岁月 提交于 2020-12-26 10:56:03
问题 I have a string containing a list of key-value pairs like this: "a:1,b:2,c:3". I would like to extract a value for a specified key so that e.g. I would get "1" for "a". I was planning to do it with a regex like this: '(?<=(^|,)$KEY:)^,*' but it seems grep doesn't support lookarounds. (I'm not even sure this regex works correctly.) Is there another way? 回答1: You may use grep -oP "(?:^|,)$KEY:\K[^,]+" The -o option outputs matches. -P enables PCRE engine. The double quotes are necessary for

grab required field values from the paragraph block using regex in python

假装没事ソ 提交于 2020-12-15 04:57:30
问题 I've a text file, from that I have extracted these two paragraph block. The text example is give below. Text Example: EXONERAR, com validade a contar de 19 de agosto de 2020 , DE- NILSON DE BRITO LIMA , ID FUNCIONAL Nº 2100423-4 , do cargo em comissão de Coordenador , símbolo DAS-8 , da Coordenadoria de Gestão Centralizada de Serviços, da Superintendência de Gestão Centralizada, da Subsecretaria de Logística , da Secretaria de Estado de Planejamento e Gestão . Processo nº SEI- 120001/010643

python regex match full paragraph including new line

◇◆丶佛笑我妖孽 提交于 2020-12-13 03:36:24
问题 I've a text file, from that I want to match the full paragraph block but my current regex doesn't work to match full paragraph including the new line. Text Example: NOMEAR JOSIAS CARLOS BORRHER do cargo em comissão OTHER TEXT GOES HERE .................... 020007/002832/2020. EXONERAR DOUGLAS ALVES BORRHER do cargo em comissão OTHER TEXT GOES HERE .................... 020007/002832/2020. NOMEAR RAFAEL DOS SANTOS PASSAGEM para exercer o cargo OTHER TEXT GOES HERE .................... 020007

python regex match full paragraph including new line

烂漫一生 提交于 2020-12-13 03:36:15
问题 I've a text file, from that I want to match the full paragraph block but my current regex doesn't work to match full paragraph including the new line. Text Example: NOMEAR JOSIAS CARLOS BORRHER do cargo em comissão OTHER TEXT GOES HERE .................... 020007/002832/2020. EXONERAR DOUGLAS ALVES BORRHER do cargo em comissão OTHER TEXT GOES HERE .................... 020007/002832/2020. NOMEAR RAFAEL DOS SANTOS PASSAGEM para exercer o cargo OTHER TEXT GOES HERE .................... 020007