DataAnnotation RegularExpression problems

Why RegularExpressionAttribute validation doesn't compare the input string with the value of all matches concatenated? I asked a question here about the scenario below, but I found a solution the next day and found it better to raise the issue here....
more »

2017-12-03 19:12 (2) Answers

Positive lookbehind on non-ASCII characters in R

I have an R function which tries to capitalise the first letter of every "word" proper = function(x){ gsub("(?<=\\b)([[:alpha:]])", "\\U\\1", x, perl = TRUE) } This works pretty well, but when I have a word with a Māori macron in it like Mā...
more »

2017-12-02 07:12 (2) Answers

Remove hex values from data.table in R

I have a large data table called Site (300,000 rows, 100 columns). Throughout the data table are hex values, for example: "\x96" or "\xc9." I want all of these values to be removed. They follow the format of "\x" followed by two characters (numbers o...
more »

2017-12-01 20:12 (1) Answers

Parse RegEx IP matches in Powershell array

I am trying to work out how to parse an array for IP addresses. I have already worked out how to resolve the IP to DNS Hostname so far I have this: Function Get-IP-Hostname { Param([string[]]$array) $array.length foreach ($element in $...
more »

2017-12-01 18:12 (3) Answers

Remove accents in string except "ñ"

I have the following example code: var inputString = "ñaáme"; inputString = inputString.Replace('ñ', '\u00F1'); var normalizedString = inputString.Normalize(NormalizationForm.FormD); var result = Regex.Replace(normalizedString, @"[^ñÑa-zA-Z0-9\...
more »

2017-11-25 18:11 (1) Answers

Regex pattern questions in r

I need to match author and time from string in R. test = "Postedby BeauHDon Friday November 24, 2017 @10:30PM from the cost-effective dept." I am currently using gsub() to find the desired output. Expected output would be: #author "BeauHDon" #...
more »

2017-11-25 07:11 (1) Answers

Why is a compiled python regex slower?

In another SO question, the performance of regexes and Python's in operator were compared. However, the accepted answer uses re.match, which only matches the beginning of a string, and thus behaves completely different to in. Also, I wanted to see th...
more »

2017-11-24 17:11 (1) Answers

Regular Expression to match some strings

I want to find any string from the following set of strings from the user's input: Password@123 Pa$$w0rd@123 Password#123 Pa$$w0rd#123 Password_123 Pa$$w0rd_123 The digits at the end should be of the min length 3 & max 6. And this is the rege...
more »

2017-11-23 23:11 (3) Answers

Return which optional pattern was matched

I'm wondering how can i obtain which pattern in regex was matched. I have this regex (i'm using .match in Ruby): (?i)(penalty is\W+[0-9]+\W+night)|(penalty of\W+[0-9]+\W+) Now i know how to return matched text in string, but is there a way to get...
more »

2017-11-23 16:11 (3) Answers

String extract, to extract number from a text

How can I extract a 3 digit number from text which is not a date? Example: "she is born on 02-05-1934 and she is 200 years old." So, how do i extract 200 from here I was using the code: str_extract(data,"[[:digit:]]{3}") but it's returning...
more »

2017-11-23 09:11 (1) Answers

Extract substring and numbers from a string in R

I have several strings, following are some examples. rfoutputtablep7q10000t20000c100 rfoutputtablep7q1000t20000c100 svmLinear2outputtablep7q20000t20000c100 svmLinear2outputtablep7q5000t20000c100 I want to make a data frame with columns: algorithm...
more »

2017-11-21 17:11 (4) Answers

Regex with DOMDocument in PHP

Consider the following PHP snippet: <?php $html = <<<DATA <p>Lorem Ipsum is simply dummy text</p> <p>Lorem Ipsum is <a href="http://www.google.com">simply</a> dummy text</p><a href="http://www.yout...
more »

2017-11-20 21:11 (2) Answers

Using regular expressions in views.py Django?

I have a form in my Django app where one field is called url. The user can add a youtube url. On submit, I want to save only the video id. My views.py look like this: import re def video_new(request): if request.user.is_authenticated(): ...
more »

2017-11-19 23:11 (2) Answers

RegEx match with whitespace but exclude in Output

I am trying to match multiple lines in source code between starting and ending markers (<% and %>), but I need the output variable (if that's what it is called) to exclude any surrounding newlines at the end of the matched code block. Because I...
more »

2017-11-18 17:11 (1) Answers