haskell regex substitution

I don’t think “just roll your own” is a reasonable answer to people trying to get actual work done, in an area where every other modern language has a trivial way to do this. Including Scheme. So here’s some actual resources; my code is from a project where I was trying to replace “qql foo … Read more

Git add lines to index by grep/regex

patchutils has a command grepdiff that can be use to achieve this. # check that the regex search correctly matches the changes you want. git diff -U0 | grepdiff ‘regex search’ –output-matching=hunk # then apply the changes to the index git diff -U0 | grepdiff ‘regex search’ –output-matching=hunk | git apply –cached –unidiff-zero I use … Read more

What is (\d+)/(\d+) in regex?

Expanding on minitech’s answer: ( start a capture group \d a shorthand character class, which matches all numbers; it is the same as [0-9] + one or more of the expression ) end a capture group / a literal forward slash Here is an example: >>> import re >>> exp = re.compile(‘(\d+)/(\d+)’) >>> foo = … Read more

What is the equivalent of Regex-replace-with-function-evaluation in Java 7?

Your answer is in the Matcher#appendReplacement documentation. Just put your function call in the while loop. [The appendReplacement method] is intended to be used in a loop together with the appendTail and find methods. The following code, for example, writes one dog two dogs in the yard to the standard-output stream: Pattern p = Pattern.compile(“cat”); … Read more

RegEx Match multiple times in string

Use a positive look ahead and look behind assertion to match the angle brackets, use .*? to match the shortest possible sequence of characters between those brackets. Find all values by iterating the MatchCollection returned by the Matches() method. Regex regex = new Regex(“(?<=<<).*?(?=>>)”); foreach (Match match in regex.Matches( “this is a test for <<bob>> … Read more