|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Basic regex understanding help
(a | b) + x = ax, bx, aax, abx, bax, bbx
The values on the RHS are ones that match the regex on the LHS. However, from my interpretation, it either matches 'a' or 'b' one or more times and then 1 'x'. so, 'ax' 'aax' 'bbx' seem valid, but how come 'abx' 'bax' are valid? I thought | means 'or' so it's one or the other, 'a' or 'b' one or more times? |
|
#2
|
|||
|
|||
|
You've got the grouping mixed up. Take it apart.
(a|b) -- matches either 'a' or 'b'. (a|b)+ -- matches one or more repetitions of (a|b), so 'a', 'b', 'aa', 'ab', 'ba', 'bb', 'aba', etc. are all good. Any string is good as long as each character individually matches (a|b). (a|b)+ is not the same as (a+|b+). |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > Basic regex understanding help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|