Questions tagged [regex-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 "|".

39 questions
1
vote
5 answers

I want a regex support for characters that uses IP Address with Subnet

I have a regex ^[a-zA-Z0-9.*?]+$ that supports IP addresses like 31.202.216.280 how can I modify the given regex in a way where I could support subnets with an IP address like so 31.202.216.280/38
misbha afreen
  • 33
  • 1
  • 6
1
vote
1 answer

Regex in Python: Separate words from numbers JUST when not in list (Variable exception)

This question is related to this one. I'd like to have variable exceptions which can receive a list of alphanumeric variables or null. For instance, I have a dummy function that returns possible alphanumeric values which such letters and numbers…
John Barton
  • 1,581
  • 4
  • 25
  • 51
1
vote
1 answer

How to search a string for values and convert values

I have an API that accepts a string that needs to be properly formatted before going into the server. The format for going into the server is the following "{Country ABR} {Day/Hour} {State ABR} {Title} {hrs.} ({Month Year}.)" Several Possibilities…
Dylan Godfrey
  • 103
  • 2
  • 10
1
vote
3 answers

Make sed regex alternations follow left to right precedence?

I'm trying to use a regex to format some binary from xxd -b, but to demonstrate this simply I'll show you what I expect to happen: Regex to delete: /1x|1.*/ Text: 1x21y3333333313333 -> 2 Where all occurrences of 1x are deleted, then everything…
Unihedron
  • 10,902
  • 13
  • 62
  • 72
1
vote
1 answer

Regex pattern containing substring and no withespaces

I want to validate an input form in Angular, string must contain substring: facebook.com or fb.me and no whitespaces so for instance: 1) randomString -> Fail 2) www.facebook.com -> Ok 3) www.fb.me -> Ok 4) www.facebook.com/pippo pallino -> Fail…
mattobob
  • 833
  • 4
  • 15
  • 37
1
vote
1 answer

Use static string once in Regex while using two patterns with OR

Here is my regex: STATICSTRING\s[a-zA-Z]:\\[\\\S|*\S]?.*$|STATICSTRING\s\w* as you can see there are two patterns, \s[a-zA-Z]:\\[\\\S|*\S]?.*$ and \s\w* which is combined with a | operator. and the STATICSTRING is repeated in each one. Is there any…
Inside Man
  • 4,194
  • 12
  • 59
  • 119
1
vote
1 answer

Alternation group with two alternatives matching entire string

I working on a regular expression which returns 1 only in case given value is A or B. I used select 'A' REGEXP '^A|B$' The '|' symbol is behaving like "or", but the result is not as expected with AB: select 'AB' REGEXP '^A|B$' = 1 while I expect…
Farrukh
  • 43
  • 3
1
vote
2 answers

Match altered version of first match with only one expression?

I'm writing a brush for Alex Gorbatchev's Syntax Highlighter to get highlighting for Smalltalk code. Now, consider the following Smalltalk code: aCollection do: [ :each | each shout ] I want to find the block argument ":each" and then match "each"…
Max Leske
  • 5,007
  • 6
  • 42
  • 54
1
vote
3 answers

Logical OR not working in regular expression

I am working on a big log file whose entries are as follow: -- "GET /fss-w3-mtpage.php HTTP/1.1" 200 0.084 41 "-" "c110bc/1.0" 127.0.0.1:25001 0.084 -- "GET…
Vikas Verma
  • 313
  • 1
  • 5
  • 18
0
votes
1 answer

Proper way to build a compiled alternation list

I have a series of regex patterns that get grouped into categories. I'm trying to statically compile them into alternations, but I don't want any special meanings to get lost. As an example, I'm identifying Raspberry Pi GPIO pins by name. There…
RoUS
  • 1,888
  • 2
  • 14
  • 29
0
votes
0 answers

Regular Expressions Cookbook, 2nd Edition; Chapter 3.22, converting a parser to PostgreSQL

everyone! In the book Regular Expressions Cookbook written by Jan Goyvaerts, Steven Levithan, in Chapter 3.22 there is a parser example. In short, you need to write a parser that accept two types of information: Keywords: "table", "row" and…
0
votes
2 answers

Confusion Within an Alternation

Suppos that within a regex, if match one alternative from an alternation it stop right there even if still more alternatives left (there are no other tokens in the regex outside the alternation). Source This pattern that search one double word…
nEAnnam
  • 1,246
  • 2
  • 16
  • 22
0
votes
1 answer

Regex: Alternators order issue

When using alternation in regex, we should include items in the alternators in order to avoid being affected by eagerness of the engine. Then if having a list such as co,co.,co-op,association,assoc we should prefer to include them in order to get…
John Barton
  • 1,581
  • 4
  • 25
  • 51
0
votes
0 answers

Python Regex: Alternations to remove numbers under certain conditions

It is worth noting that regex engine stops eagerly searching as soon as it finds a match. Then, the order matters in certain situations because it will not continue checking the remaining options in the alternation. The purpose in this regex is…
John Barton
  • 1,581
  • 4
  • 25
  • 51
0
votes
1 answer

Match single-line comments via regex in Notepad++

Why do these two regexes yield different results in Notepad++? //.*?\n|//.*$|\s+|. (2 matches → screenshot) //.*?(?:\n|$)|\s+|. (3 matches → screenshot) Background I'm writing a primitive lexer for Delphi in Perl. The purpose is to extract words…
Wolf
  • 9,679
  • 7
  • 62
  • 108