regular-language

How to determine if a context-free grammar describes a regular language?

旧时模样 提交于 2021-02-19 07:56:05
问题 Given an arbitrary context-free grammar, how can I check whether it describes a regular language? I'm not looking for exam "tricks". I'm looking for a foolproof mechanical test that I can code. If it helps, here's an example of a CFG that I might receive as an input. Specifically, notice that the answer must be much more complicated than just looking for left- or right-recursion, since the presence of another type of recursion does not automatically imply the grammar is irregular. S: A B C D

Creating a grammar out of a regular language

断了今生、忘了曾经 提交于 2021-01-29 16:03:41
问题 I have some problems to figure out a grammar for this special language, hope you could help: The language is: Σ={x,y,z} A = { w | w ∈ Σ^∗ ∧ |w|_x mod 2 >= |w|_y mod 2 } Because this one is so hard i tried first to put all properties together in one grammar, so |w|_x mod 2 >= |w|_y mod 2 and w ∈ Σ^∗ , but without getting all combination like cacbcacb etc What I get is something like: ccccc...caa...abcbbbcc and than i use ac -> ca etc to change the combination and to get every word I want. But

Modulo operator in a regular expression

送分小仙女□ 提交于 2021-01-27 22:43:46
问题 I am attempting to write a regular expression to accept any binary strings with the only criteria being that the number of 0s is not a factor of 3 ([number of 0s] % 3 != 0). How can this be achieved? 回答1: You can use .match() to achieve this. .match() returns an array of all occurrences matching the regex. Using modulo on the returned array's .length will tell you if the number of 0s is divisible by 3. var someString = '012345167891abcd1efghi1jklmn'; var numOfOnes = someString.match(/(1)/g) /

Modulo operator in a regular expression

陌路散爱 提交于 2021-01-27 21:09:06
问题 I am attempting to write a regular expression to accept any binary strings with the only criteria being that the number of 0s is not a factor of 3 ([number of 0s] % 3 != 0). How can this be achieved? 回答1: You can use .match() to achieve this. .match() returns an array of all occurrences matching the regex. Using modulo on the returned array's .length will tell you if the number of 0s is divisible by 3. var someString = '012345167891abcd1efghi1jklmn'; var numOfOnes = someString.match(/(1)/g) /

Is L = {a^n b^m | n>m} a regular or irregular language?

梦想与她 提交于 2020-02-10 09:30:20
问题 I have troubles in solving/proving this problem. Any ideas please? 回答1: L = {a n b m | n > m} is not regular language. Yes, the problem is tricky at first few try and deserve vote-up. Pumping Lemma a necessary property of regular language is tool for formal proof that language is not regular language. Formal definition: Pumping lemma for regular languages Let L be a regular language. Then there exists an integer p ≥ 1 depending only on L such that every string w in L of length at least p ( p

Is L = {a^n b^m | n>m} a regular or irregular language?

泪湿孤枕 提交于 2020-02-10 09:29:48
问题 I have troubles in solving/proving this problem. Any ideas please? 回答1: L = {a n b m | n > m} is not regular language. Yes, the problem is tricky at first few try and deserve vote-up. Pumping Lemma a necessary property of regular language is tool for formal proof that language is not regular language. Formal definition: Pumping lemma for regular languages Let L be a regular language. Then there exists an integer p ≥ 1 depending only on L such that every string w in L of length at least p ( p

Confusion related to regular expression

为君一笑 提交于 2020-01-25 00:57:27
问题 I have this confusion related to regular expression. If there are two sets A and B then is (AB)* = A*B* ? 回答1: IN CONTEXT OF REGULAR EXPRESSION: is (AB)* = A*B*? No, (AB)* is not equals to A*B* (AB)* means ABABABABAB......AB A sequence of AB (any number of time). A*B* means AAAA.....BBB...... Any number of A's followed by any number of B's. And A can't appear after B's. Intersection - Both includes { NULL string, AB } only Example: Suppose: A = xy , and B = z (AB)* = xyzxyz.....xyz A*B* =

No \p{L} for JavaScript Regex ? Use Unicode in JS regex [duplicate]

本小妞迷上赌 提交于 2020-01-23 06:47:07
问题 This question already has answers here : Preg_match to regex equivalent expression (2 answers) Match only unicode letters (2 answers) Closed 2 years ago . I nedd to add a-zA-ZáàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ x time but I find this very ugly. So I try \p{L} but it does not working in JavaScript. Any Idea ? my actual regex : [a-zA-ZáàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ][a-zA-ZáàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ' ,"-]*[a-zA

Match product dimensions with regular expression

Deadly 提交于 2020-01-23 02:12:26
问题 I am trying to match length width and height with a regular expression. I have the following cases Artikelgewicht3,7 Kg Produktabmessungen60,4 x 46,5 x 42 cm or Artikelgewicht3,7 Kg Produktabmessungen60 x 46 x 42 or Artikelgewicht3,7 Kg Produktabmessungen60 x 46 The second case can be matched with (\d+) x (\d+) x (\d+) , which works fine. I further tried to match the first and the third case with (\d+)(\\,\d+)? x (\d+)(\\,\d+)? x (\d+)(\\,\d+)? . Any suggestions what I am doing wrong? 回答1:

Java regular expression with groups

混江龙づ霸主 提交于 2020-01-16 08:51:08
问题 I would like to replace all occurences of strings like: "{something1} "{someother2} "{thing3} but how to deal with group that contains string, not chars? -- edit: e.g. given String: sometext "{something1}hello I would like to have sometext hello or better, but its only replaceAll parameter sometext "hello 回答1: I guess you can use replaceAll: String b = a.replaceAll("\\{.*?\\}", "sometext "); This will replace all characters surrounded by curly braces with the replacement string. 回答2: Just