Questions tagged [alternation]

Anything related to regular expressions alternation operation. An alternation operation in regular expressions syntax is a way of indicating two alternative patterns which can both match the subject string. In many regular expressions flavors (notably those derived from Perl syntax) the alternation is indicated by a vertical bar "|".

Anything related to regular expressions alternation operation. An alternation operation in regular expressions syntax is a way of indicating two alternative patterns which can both match the subject string. In many regular expressions flavors the alternation is indicated by a vertical bar "|".

42 questions
45
votes
6 answers

How can I alter a MenuItem on the Options Menu on Android?

I have an Options Menu on my Activity with an MenuItem "Start". When this MenuItem is selected I would like to alter the Menu so it contains a MenuItem "Stop". And finally when "Stop" is selected, I would like to alter back to "Start". Here is parts…
Jonas
  • 121,568
  • 97
  • 310
  • 388
12
votes
3 answers

Regex is behaving lazy, should be greedy

I thought that by default my Regex would exhibit the greedy behavior that I want, but it is not in the following code: Regex keywords = new Regex(@"in|int|into|internal|interface"); var targets = keywords.ToString().Split('|'); foreach (string t…
Stomp
  • 890
  • 1
  • 6
  • 19
7
votes
2 answers

Can regexes containing ordered alternation be rewritten to use only unordered alternation?

Suppose I have a regex language supporting literals, positive and negative character classes, ordered alternation, the greedy quantifiers ?, *, and +, and the nongreedy quantifiers ??, *?, and +?. (This is essentially a subset of PCRE without…
uckelman
  • 25,298
  • 8
  • 64
  • 82
7
votes
6 answers

Is it faster to use alternation than subsequent replacements in regular expressions

I have quite a straightforward question. Where I work I see a lot of regular expressions come by. They are used in Perl to get replace and/or get rid of some strings in text, e.g.: $string=~s/^.+\///; $string=~s/\.shtml//; $string=~s/^ph//; I…
Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
7
votes
1 answer

Why does ListBox AlternationIndex always return 0

Ok, I know there are a couple of other similar questions to this but I am having a real issue with getting the AlternationIndex to work on ListBox or ListView. my xaml is such:
Kezza
  • 736
  • 9
  • 25
5
votes
1 answer

Why won't a longer token in an alternation be matched?

I am using ruby 2.1, but the same thing can be replicated on rubular site. If this is my string: 儘管中國婦幼衛生監測辦公室制定的 And I do a regex match with this expression: (中國婦幼衛生監測辦公室制定|管中) I am expecting to get the longer token as a match.…
drKreso
  • 1,030
  • 10
  • 16
3
votes
1 answer

Why regex engine choose to match pattern `..X` from `.X|..X|X.`?

I have a string 1234X5678 and I use this regex to match pattern .X|..X|X. I got 34X The question is why didn't I get 4X or X5? Why regex choose to perform the second pattern?
fronthem
  • 4,011
  • 8
  • 34
  • 55
3
votes
2 answers

Regex to collect data after one search term and before one of two others (which ever is first)

I need to fashion a regex with the following requirements: Given sample text: SEARCH_TERM_#1 find this text SEARCH-TERM_#2_more text_SEARCH-TERM_#3 SEARCH_TERM_#1 find this text SEARCH-TERM_#3 I want to extract the string which appears in the find…
a_hanif
  • 157
  • 7
2
votes
4 answers

How to prioritize regex | (OR) expressions?

I'm trying to match kanji compounds in a Japanese sentence using regex. Right now, I'm using / ((.)*) /to match a space delimited compound in, for example, 彼はそこに ひと人 でいた。 The problem is, that in some sentence the word is at the beginning, or…
Philip Seyfi
  • 929
  • 1
  • 10
  • 24
2
votes
1 answer

Escape brackets in a regex with alternation

I am trying to write a Reg Expression to match any word from a list of words but am having trouble with words with brackets. This is the reg expression I have so far: ^\b(?:Civil Services|Assets Management|Engineering Works (EW)|EW…
masterg174
  • 143
  • 9
2
votes
2 answers

How to use a list of vectors in alternation (regular expressions)

Is it possible to parse a vector of character strings to an alternation element in a regular expression? For example: pattern <- "^This\\s(*alternation element*)\\srocks\\." Animals <- c("cow","dog","cat") So if I would then parse "Animals" to the…
MtH
  • 43
  • 5
2
votes
0 answers

How Does Alternation Differ From Boolean Or?

I am trying to write a Regular Expression to read real literals based on this graph: I found that this solution works: ([0-9]+(\.[0-9]+)?[Ee][\+\-]?[0-9]+)|([0-9]+\.[0-9]+) Notice the two parts separated via alternation:…
Caleb Robinson
  • 1,010
  • 13
  • 21
2
votes
2 answers

Perl uninitialized value when using alternation in regex

I have a for loop with an if statement that looks like this: for (my $i=0; $i < $size; $i++) { if ($array[$i] =~ m/_(B|P|BC|PM)/) { #Remove from @array splice(@array, $i, 1); next; } #Get rid…
N Lindsay
  • 23
  • 2
1
vote
1 answer

Troubles with Java regex and alternation

I'm having troubles getting a regex to work. I'm trying to parse a large, multiline block of text for certain XML tags. The reason I'm not parsing this with an XML library however is it's actually part of a block of ESQL as well. The line I'm…
Feynt
  • 68
  • 1
  • 8
1
vote
2 answers

Jquery toggle using 2 elements

this is my script, I'm using a toggle so I can animate a sliding menu. $("div.show-menu").click().toggle( function() { // first alternation $("#slideover").animate({ right: "512px" …
Joshc
  • 3,825
  • 16
  • 79
  • 121
1
2 3