Menu
  • HOME
  • TAGS

Python regex for parsing version strings and look behind fixed width

python,regex,lookbehind,negative-lookbehind

You need to use negative lookahead assertion to make (?P<pre_x>\w+) to match any except for centos or redhat. ^(?P<prod>\w+)-(?P<maj>\d)\.(?P<min>\d)\.(?P<bug>\d)(?:-(?P<pre>alpha|beta|rc)(?:\.(?P<pre_n>\d))?(?:\.(?:(?!centos|redhat)\w)+)?)?(?:\.(?P<os>centos|redhat))?(?:\.(?P<plat>snb|ivb))?$ DEMO...

On Cygwin (or windows 7), match a word, look backwards, skip a word and print x number of comma separated words

regex,awk,grep,finance,lookbehind

Since this is just a simple subsitution on a single line it's really most appropriate for sed: $ sed -n -r 's/(^Revenue)(,[^,]*){3}(.*),[^,]*,"\t\t".*/\1\3/p' file Revenue,444.000,333.000,222.000,111.00 but you can do the same in awk with gensub() (gawk) or match()/substr() or similar. It will run in the blink of an eye no matter...

Regex issue i am stuck with

c#,regex,lookbehind,negative-lookbehind

You can use the following update of your regex: ^(?:0?[1-9]|1[0-2])\s*[-−—]\s*(?:0?[1-9]|1[0-2])\s*/\s*\s*2[01][0-9]{2}$ See demo It will not match 12-30/2014, 12-31/2014, 12-32/2014, 13-31/2014, 20-6/2014. It will match 1-6/2011 and 02-12/2014. C#: var lines = "1-6/2011\r\n02-12/2014\r\n12-30/2014\r\n12-31/2014\r\n12-32/2014\r\n13-31/2014\r\n20-6/2014"; var finds = Regex.Matches(lines, @"^(?:0?[1-9]|1[0-2])\s*[-−—]\s*(?:0?[1-9]|1[0-2])\s*/\s*\s*2[01][0-9]{2}\r?$", RegexOptions.Multiline); Mind that \r? is only necessary in case we...

Conditional look-behind (python regex), how to exclude certain words but include certain words?

python,regex,lookbehind

I think the answer provided by hwnd above is the best way to go ^(?!Not valid\b).*(?:at|in)(.*)\.$ but to answer your question, what you're trying to accomplish is this (?<=(?<!not valid )(?:at|in) ).*(?=\.) Demo...

javascript regex lookbehind and jQuery selector

javascript,jquery,regex,lookbehind

The expression should match at least one s if it not preceded by a single quote. Since you really don't want to work with the matches, only test if there is a match at all, you don't really need a lookbehind. You only need to make sure that it...

Parsing text between quotes with .NET regular expressions

c#,.net,regex,lookahead,lookbehind

You can use a very useful .NET regex feature where multiple same-named captures are allowed. Also, there is an issue with your (?<name>) capture group: it allows a digit in the first position, which does not meet your 1st requirement. So, I suggest: (?si)(?:(?<=\s)|^)@(?<name>\w+[a-z0-9_-]+?)\s*=\s*(?:(?<value>[a-z0-9_-]+)|(?:"")?(?<value>.+?)(?=(?<!\\)"")) See demo Note that you cannot...

grep regex lookahead or start of string (or lookbehind or end of string)

regex,grep,lookahead,lookbehind

If you're using grep, you must be using the -P option, or lookarounds and \K would throw errors. That means you also have negative lookarounds at your disposal. Here's a simpler version of your regex: (?<!\w)n\.b\.(?!\w) Also, be aware that (?<=...) and (?<!...) are lookbehinds, and (?=...) and (?!...) are...

Vim positive lookbehind bug?

regex,vim,lookbehind

Yes, this looks like a bug. I can reproduce with Vim 7.4.608, but only with the default :set regexpengine=0 automatic selection. To avoid the problem, you can either change the global option, or explicitly specify an engine inside the pattern: \%#=1\(Hello\n\)\@<=A \%#=2\(Hello\n\)\@<=A Please report this bug, either to the vim_dev...

Regex: multiple lookbehinds

regex,terminal,grep,lookbehind

You could use the below grep command which uses a PCRE regex. grep -oP '^alias(?:\s+-g)?\s+\K[^=]+(?==)' file OR grep -oP '^alias(?:\s+-g)?\s+\K\w+' file OR $ grep -oP '^alias(?:\s+-g)?\s+\K[^=]+' file NULL l \K discards the previously matched characters from printing at the final. \K keeps the text matched so far out of the...

What is the RegEx for this match?

regex,vb.net,lookbehind,quantifiers

Get it at matched group 1 that is captured by using parenthesis () String literals for use in programs: @"item\[\d+\].*?=\s+(\d+);" Tested it here...

How can I implement variable width look behind regex to get a list of items?

php,regex,lookbehind

Use the below regex and get the count from group index 1 and fruit name from group index 2. (?:^fruits|(?<!^)\G)\h*\K(?<count>\d*)\h*(?<fruit>\w*) DEMO...

grepl in R: matching impeded by intra-word dashes

regex,r,lookahead,lookbehind,grepl

I think this matches the description in your comment of what you want to accomplish. spaceInvader <- function(a, b, text) { # look ahead of `a` to see if there is a space hasa <- grepl(paste0(a, '(?= )'), text, perl = TRUE) # look behind `b` to see if there...

Need to find a labeled number in a text field - regular expression lookbehind won't work

regex,oracle11g,keyword,substr,lookbehind

You can use REGEXP_REPLACE, like this: select REGEXP_REPLACE(s, '^.*?PI?N ?#? ?(\d{1,20}).*$|^.*?(\d{1,20}) ?PI?N.*$', '\1\2') from test; The idea is to match the entire string from ^ to $, but put only the pin portion into the capturing group parentheses. After that use \1 and \2 syntax to extract the value of...

How to use '\' in Python lookbehind assertion regex (?<=\\) to match C++-like quoted strings

python,regex,backslash,lookbehind

EDIT: The final regex is an adaptation from the regex provided at Word Aligned I think you are looking for this regex: (?s)"(?:[^"\\]|\\.)*" See demo on regex101. Sample Python code (tested on TutorialsPoint): import re p = re.compile(ur'(?s)"(?:[^"\\]|\\.)*"') ms = p.match('"my s\\"tr"; 5;') print ms.group(0) ...