regular-language

Swedish SSN Regular expression reject users under a specific age

强颜欢笑 提交于 2019-12-10 13:48:52
问题 I Have a problem with my regular expression. I have made it possible to valdiate correct swedish social security number to match these criteria. YYMMDDNNNN YYMMDD-NNNN YYYYMMDDNNNN YYYYMMDD-NNNN But i would also like to reject a user to register if the user is under 18 years old. My reqular expression is looking like this at the moment: Do anyone encountered the same problem with the age range Swedish SSN? private const string RegExForValidation = @"^(\d{6}|\d{8})[-|(\s)]{0,1}\d{4}$"; UPDATE

Aren't modern regular expression dialects regular?

一个人想着一个人 提交于 2019-12-09 04:37:37
问题 I've seen a few comments here that mention that modern regular expressions go beyond what can be represented in a regular language. How is this so? What features of modern regular expressions are not regular? Examples would be helpful. 回答1: The first thing that comes to mind is backreferences: (\w*)\s\1 (matches a group of word characters, followed by a space character and then the same group previously matched) eg: hello hello matches, hello world doesn't. This construct is not regular (ie:

How to parse Json using Regex?

梦想与她 提交于 2019-12-09 03:54:19
问题 I want to parse this json data with regex. But, i could not. I tried like this module.getid(.*) , but no working. Only, I want to take this part -> module.getid(...) module.getid([{"id":"44423"}]); module.getresult([{"result":"false"}]); How can i do it? 回答1: Try this if you want to capture the first (demo): /module.getid\((.*?)\); *module.getresult(?:.*?)\);$/m If you want to capture both json strings (demo): /module.getid\((.*?)\); *module.getresult(.*?)\);$/m 回答2: Well, to work from that

Find the regular expression for the language on E={a,b}

安稳与你 提交于 2019-12-08 13:11:36
问题 L = w : (na(w) - nb(w)) mod 3 /= 0 How can I go about finding the regular expression for this language? I understand that it means that the number of As minus the number of Bs cannot be a multiple of 3. So a - b cannot be 3,6,9,12, etc. But I am still having trouble putting it into a regular expression. I tried first making it a DFA or NFA but I couldn't do that either. Any help is appreciated! 回答1: I would go about it by dividing the list of words on {a,b} into three cases: L1 = w : (na(w) -

is a* the same as (a*)*?

拟墨画扇 提交于 2019-12-07 15:52:02
问题 Quick question, if a is a regular expression then is it true that a* = (a*)* ? Is (a*)* a valid expression? If it is, then can anyone explain why is it the same as a* ? I apologize for asking here, but I couldn't find anything via Google. 回答1: Yes , a*=(a*)* are same. Both generate same language that is string any numbers a's including null . L(a*) = {^, a, aa, aa...... } = L ((a*)*) Is (a*)* a valid expression? Yes, this expression is called REGULAR-EXPRESSION (I saw you missed the tag). Any

Proving a Certain Language Regular

丶灬走出姿态 提交于 2019-12-07 05:39:29
问题 In my computational theory class we have an assignment of proving a language is regular. The language is defined as: B = { 1 k y | y is in {0, 1}* and y contains at least k 1s, for k >= 1 } This language looks to me like it would need a pushdown automata to create a machine for this but if someone could push me in the right direction to try and prove this is a regular language. Showing me one of these ways to prove it: creating a NFA, DFA, regular expression, or regular grammar would be

Pumping lemma (Regular language)

余生颓废 提交于 2019-12-07 05:04:05
问题 I need some help with a pumping lemma problem. L = { {a,b,c}* | #a(L) < #b(L) < #c(L) } This is what I got so far: y = uvw is the string from the pumping lemma. I let y = abbc^n, n is the length from the pumping lemma. y is in L because the number of a:s is less than the number of b:s, and the number of b:s is less than the number of c:s. I let u = a, v = bb and w = c^n. |uv| < y, as stated in pumping lemma. If I "pump" (bb)^2 then i get y = abbbbc^n which violates the rule #b(L) < #c(L). Is

substring match faster with regular expression?

那年仲夏 提交于 2019-12-07 01:04:21
问题 After having read up on RE/NFA and DFA, it seems that finding a substring within a string might actually be asymptotically faster using an RE rather than a brute force O(mn) find. My reasoning is that a DFA would actually maintain state and avoid processing each character in the "haystack" more than once. Hence, searches in long strings may actually be much faster if done with regular expressions. Of course, this is valid only for RE matchers that convert from NFA to DFA. Has anyone

Regular languages vs. non-regular ones [closed]

南笙酒味 提交于 2019-12-07 00:07:20
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Can anyone kindly help me distinguish between regular languages (i.e. those that can be described by regular expressions) and other languages that are not regular in terms of the formal definition of regular languages? Furthermore, can you provide some examples on both sides? 回答1: Regular languages are defined

Regular expression for [a-zA-Z] [closed]

对着背影说爱祢 提交于 2019-12-06 07:23:57
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I have a regular expression that matches English letters only, a [a-zA-Z] character class. Is there any built-in regular expression for that? I mean something like \s or \w . 回答1: You are asking for a shorthand class for English letters. In case you are using POSIX-compliant regex