Small confusion in regex at | (pipe) -


when use pattren

"(see|see also) [\w\d]+" 

on text

see page  see page 

but output matches is

see page  see 

if im interchanged see, see also

"(see also|see) [\w\d]+" 

the output

see page  see page 

i thought both same. may know why happen?

removing alternation , leaving see [\w\d]+ match string "see page" because satisfied see also. way regular expressions work alternation (at least in case) attempt match each option in order rest of pattern , stop successfully, or go alternatives when fails. when reverse alternation, tries match see also first, fail "see page."

it make more sense write see( also)? [\w\d]+


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -