regular-language

Select part of line in regular expression

纵饮孤独 提交于 2019-12-04 06:48:40
问题 I have this string: #1#http://test.ir:8080/srvSC.svc#1# #2#http://test.ir:8081/srvSC.svc#2# #3#http://test.ir:8082/srvSC.svc#3# #4#http://test.ir:8083/srvSC.svc#4# #5#http://test.ir:8084/srvSC.svc#5# #6#http://test.ir:8085/srvSC.svc#6# I want to select all #1# #2# ... so in order to i wrote this expression : ^(^\#.\#) but it just select first line.How could i select first #.# and last of #.# ? 回答1: You can use ^(#\d+#)(.+)\1$ That will capture the first # s in a group, repeat any characters,

Is it possible to have regexp that matches all valid regular expressions?

梦想的初衷 提交于 2019-12-04 06:10:45
Is it possible to detect if a given string is valid regular expression, using just regular expressions? Say I have some strings, that may or may not be a valid regular expressions. I'd like to have a regular expression matches those string that correspond to valid regular expression. Is that possible? Or do I have use some higher level grammar (i.e. context free language) to detect this? Does it affect if I am using some extended version of regexps like Perl regexps? If that is possible, what the regexp matching regexp is? No, it is not possible. This is because valid regular expressions

If we know a CFG only generates regular language, can we get the corresponding regular expression?

↘锁芯ラ 提交于 2019-12-04 02:50:16
As we know, given a regular grammar, we have algorithm to get its regular expression. But if the given grammar is context-free grammar (but it only generates regular language), like S->aAb A->bB B->cB|d Is there any existing algorithm that can get the regular expression in general? Thanks! In the most general sense, there is no solution. The problem of determining whether a CFG is regular is undecidable (Greibach Theorem, last 3 pages of http://www.cis.upenn.edu/~jean/gbooks/PCPh04.pdf ) If we could convert CFGs to Regular Expressions, we could use that algorithm on any grammar and use its

Representing identifiers using Regular Expression

女生的网名这么多〃 提交于 2019-12-03 22:43:51
The regular definition for recognizing identifiers in C programming language is given by letter -> a|b|...z|A|B|...|Z|_ digit -> 0|1|...|9 identifier -> letter(letter|digit)* This definition will generate identifiers of the form identifier: [_a-zA-Z][_a-zA-Z0-9]* My question now is how do you limit the length of the identifier that can be generated to not more than 31 characters. What changes need to be made in the regular definition or how to write a regular expression to limit it to not more than the specified length. Could anyone please help. Thanks. Oscar Mederos The regular expression you

Regular expression for strings with even number of a's and odd no of b's

半世苍凉 提交于 2019-12-03 16:14:15
问题 Im having a problem in solving the problem:- Its an assignment, i solved it, but it seems to be too long and vague, Can anyboby help me please...... Regular expression for the strings with even number of a's and odd number of b's where the character set={a,b}. 回答1: One way to do this is to pass it through two regular expressions making sure they both match (assuming you want to use regular expressions at all, see below for an alternative): ^b*(ab*ab*)*$ ^a*ba*(ba*ba*)*$ Anything else (and, in

Is there a way to negate a regular expression?

北慕城南 提交于 2019-12-03 09:00:19
问题 Given a regular expression R that describes a regular language (no fancy backreferences). Is there an algorithmic way to construct a regular expression R* that describes the language of all words except those described by R ? It should be possible as Wikipedia says: The regular languages are closed under the various operations, that is, if the languages K and L are regular, so is the result of the following operations: […] the complement ¬L For example, given the alphabet {a,b,c} , the

Regular expression for strings with even number of a's and odd no of b's

删除回忆录丶 提交于 2019-12-03 05:28:48
Im having a problem in solving the problem:- Its an assignment, i solved it, but it seems to be too long and vague, Can anyboby help me please...... Regular expression for the strings with even number of a's and odd number of b's where the character set={a,b}. One way to do this is to pass it through two regular expressions making sure they both match (assuming you want to use regular expressions at all, see below for an alternative): ^b*(ab*ab*)*$ ^a*ba*(ba*ba*)*$ Anything else (and, in fact, even that) is most likely just an attempt to be clever, one that's generally a massive failure. The

chomsky hierarchy in plain english

China☆狼群 提交于 2019-12-02 17:30:35
I'm trying to find a plain (i.e. non-formal) explanation of the 4 levels of formal grammars (unrestricted, context-sensitive, context-free, regular) as set out by Chomsky. It's been an age since I studied formal grammars, and the various definitions are now confusing for me to visualize. To be clear, I'm not looking for the formal definitions you'll find everywhere (e.g. here and here -- I can google as well as anyone else), or really even formal definitions of any sort. Instead, what I was hoping to find was clean and simple explanations that don't sacrifice clarity for the sake of

Select part of line in regular expression

。_饼干妹妹 提交于 2019-12-02 11:41:30
I have this string : #1#http://test.ir:8080/srvSC.svc#1# #2#http://test.ir:8081/srvSC.svc#2# #3#http://test.ir:8082/srvSC.svc#3# #4#http://test.ir:8083/srvSC.svc#4# #5#http://test.ir:8084/srvSC.svc#5# #6#http://test.ir:8085/srvSC.svc#6# I want to select all #1# #2# ... so in order to i wrote this expression : ^(^\#.\#) but it just select first line.How could i select first #.# and last of #.# ? You can use ^(#\d+#)(.+)\1$ That will capture the first # s in a group, repeat any characters, and then match the same characters that were matched in the first group. The string you want will be in the

Why is {a^n a^n | n >= 0} regular?

半世苍凉 提交于 2019-12-01 11:53:38
I understand the reason and the proof why {a^n b^n | n >= 0} is NOT regular. Why is {a^nb^n | n >= 0} not regular? The solution of one of my exercises is: {a^n a^n | n >= 0} is regular. How can I prove this thesis? Grijesh Chauhan Yes, Language {a n a n | n >= 0} is a regular language . To proof that certain language is regular, you can draw its dfa/regular expression. And you can drive do for this language as follows: Because " a n a n for n >= 0 " is same as " a 2n for n >=0", and that is "set of all string contests of even number of symbol a " that is regular — regular expression for this