English 中文(简体)
1. Haskell的定期表述
原标题:Haskell regular expression syntax

EDIT: 工作管理机构(第二组):

(^|[ ,	
]+)([0-9\.]+)($|[ ,	
]+)

原定员额:

I m new to Haskell, aiming to use text.Regex ( From regex-compat) to extracts Value from a string. 我希望我能与任何一系列数字和时间相匹配,这些数字和期限至少有一个分离特性与左边和右边。 这是我写的:

regex = "[^ 	
,]+([0-9\.])+[$ 	
,]+"

EDIT:我最初认为,这在Schala是正常的,但现在我完全相信,我只是带着我的试卷str。 这在Haskell没有工作。 例如:

matchRegexAll (mkRegex regex) " 12.34 "

产量

Just (" ","12.34 ","",["4"])

在我看来,它应当产生结果。

Just (""," 12.34 ","",["12.34"])

Another example:

matchRegexAll (mkRegex regex) "12.34"

产量

Nothing

when it I think it should yield

Just ("","12.34","",["12.34"])

I m guessing the parser 处理“^”和“$”的方式与Schala parser不同,但所有I ve都是如此。

最佳回答

Inside a character class like [^ ,], normal regex metacharacters (such as ^ and $) lose their special meaning; they match themselves instead.1 Something like (^|[ ,]) should do what you want.

我感到惊讶的是,你在Schala的reg工作;我从未看到过一种以这种方式行事的reg。

<>1> 虽然FlopCoder指出,但^ >,在性质类别开始时,实际上negates/em>。

问题回答

www.un.org/spanish/ga/president 使用<>条码[和<条码>。 如果您希望从开始就把reg/条码同起来,则在reg开始之初就将<条码>。

如果你想将其用作座标的结尾,请上<条码>。

This "[^ ,]+([0-9\.])+[$ ,]+" matches a nonempty sequence of characters which are none of , , , , ] greedily, a nonempty sequence of digits or dots, and a nonempty sequence of any of "$ ,", capturing the penultimate of the sequences. The first matches " 12.3", the second/penultimate is only left to match "4".





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...