regex-lookarounds

Raku regex: How to use capturing group inside lookaheads

落爺英雄遲暮 提交于 2021-02-20 06:32:30
问题 How can I use capturing groups inside lookahead assertion? This code: say "ab" ~~ m/(a) <?before (b) > /; returns: 「a」 0 => 「a」 But I was expecting to also capture 'b'. Is there a way to do so? I don't want to leave 'b' outside of the lookahead because I don't want 'b' to be part of the match. Is there a way to capture 'b' but still leave it outside of the match? NOTE: I tried to use Raku's capture markers, as in: say "ab" ~~ m/<((a))> (b) /; 「a」 0 => 「a」 1 => 「b」 But this does not seem to

Raku regex: How to use capturing group inside lookaheads

随声附和 提交于 2021-02-20 06:32:14
问题 How can I use capturing groups inside lookahead assertion? This code: say "ab" ~~ m/(a) <?before (b) > /; returns: 「a」 0 => 「a」 But I was expecting to also capture 'b'. Is there a way to do so? I don't want to leave 'b' outside of the lookahead because I don't want 'b' to be part of the match. Is there a way to capture 'b' but still leave it outside of the match? NOTE: I tried to use Raku's capture markers, as in: say "ab" ~~ m/<((a))> (b) /; 「a」 0 => 「a」 1 => 「b」 But this does not seem to

Raku regex: How to use capturing group inside lookaheads

一世执手 提交于 2021-02-20 06:29:33
问题 How can I use capturing groups inside lookahead assertion? This code: say "ab" ~~ m/(a) <?before (b) > /; returns: 「a」 0 => 「a」 But I was expecting to also capture 'b'. Is there a way to do so? I don't want to leave 'b' outside of the lookahead because I don't want 'b' to be part of the match. Is there a way to capture 'b' but still leave it outside of the match? NOTE: I tried to use Raku's capture markers, as in: say "ab" ~~ m/<((a))> (b) /; 「a」 0 => 「a」 1 => 「b」 But this does not seem to

Regex in Python: Separate words from numbers JUST when not in list

依然范特西╮ 提交于 2021-02-19 05:40:30
问题 I have a list containing some substitutions which I need to keep. For instance, the substitution list: ['1st','2nd','10th','100th','1st nation','xlr8','5pin','h20'] . In general, strings containing alphanumeric characters need to split numbers and letters as follows: text= re.sub(r'(?<=\d)(?=[^\d\s])|(?<=[^\d\s])(?=\d)',' ',text,0,re.IGNORECASE) The previous regex pattern is separating successfully all numbers from characters by adding space between in the following: Original Regex ABC10 DEF

Negative look ahead not working as expected

∥☆過路亽.° 提交于 2021-02-17 01:55:12
问题 I have a bizarre situation where positive lookahead works as expected but negative lookahead doesn't. Please take a look at the following code: <?php $tweet = "RT @Startup_Collab: @RiseOfRest is headed to OMA & LNK to #showcase our emerging #startup ecosystem. Learn more! https://example.net #Riseof…"; $patterns=array( '/#\w+(?=…$)/', ); $tweet = preg_replace_callback($patterns,function($m) { switch($m[0][0]) { case "#": return strtoupper($m[0]); break; } },$tweet); echo $tweet; I want to

Multiple Conditions in Validation Regex

感情迁移 提交于 2021-02-15 06:54:45
问题 I am more or less a regex novice. I tried to get the following conditions into a regex: No White Space at the beginning and at the end of a string Allow all digits Allow spaces, points, brackets, plus and minus Resulted in the following regex: ^\S[\d\/. ()\-+]*\S$ But now i try to apply two more conditions: Allow only one or two + Allow only one ( and one ) My problem is how to merge those two conditions into the existing regex string above cuz excluding + [+]{1,2} and () [(]{1} [)]{1} doesn

Multiple Conditions in Validation Regex

蓝咒 提交于 2021-02-15 06:54:12
问题 I am more or less a regex novice. I tried to get the following conditions into a regex: No White Space at the beginning and at the end of a string Allow all digits Allow spaces, points, brackets, plus and minus Resulted in the following regex: ^\S[\d\/. ()\-+]*\S$ But now i try to apply two more conditions: Allow only one or two + Allow only one ( and one ) My problem is how to merge those two conditions into the existing regex string above cuz excluding + [+]{1,2} and () [(]{1} [)]{1} doesn

C# Regex - only match if substring exists?

允我心安 提交于 2021-02-13 17:28:45
问题 Ok, so I think I've got a handle on negation - now what about only selecting a match that has a specified substring within it? Given: This is a random bit of information from 0 to 1. This is a non-random bit of information I do NOT want to match This is the end of this bit This is a random bit of information from 0 to 1. This is a random bit of information I do want to match This is the end of this bit And attempting the following regex: /(?s)This is a random bit(?:(?=This is a random).)*

Python find and replace strings in files with argument that the string is quoted and not part of bigger string

痞子三分冷 提交于 2021-02-11 15:45:56
问题 i need a solution to the following problem. I want to replace a dynamic string if found in a file but only if there are quotes surrounding the string, either next to it or with max two spaces between, and not be part of bigger string (in python) : ori = 'testing' rep = 'posting' file contents: Line1 This is one line with some words for testing purposes Line2 this is the seconds "testing" function. Line3 that is one more " testing" line Line4 "testing" Line5 " testing" Line6 "testing " Line7 "

Regex for Markdown Emphasis

若如初见. 提交于 2021-02-10 14:51:39
问题 I'm trying to match the following markdown text for emphasis: _this should match_ __this shouldn't__ _ neither should this _ _nor this _ this _should match_as well_ __ (double underscore, shouldn't match) The issue that I'm facing with my own efforts as well as other solutions on SO is that they still end up matching the third line: _ neither should this _ Is there a way to check of my particular use case? I'm aiming this for browser applications, and since Firefox and Safari are yet to