We of course could use either perl or ssed (see post). Here's an example. Consider:
Code: Select all
a.so.b
Code: Select all
^((?![.]so[.]).)*([.]so[.])(.*)$
**uses negative lookahead. See:
https://www.regular-expressions.info/lookaround.htm
https://www.regular-expressions.info/refadv.html
Now say, we don't know if there will be a ".so.b" then we might try this
Code: Select all
^((?![.]so[.]).)*(?:([.]so[.])(.*))?$
but with the test string "ab" it doesn't work. It only matches "b"...well sort of. The full match is "ab" but there is only one capture group which is "b". So what am missing?
Here are some related links:
https://stackoverflow.com/questions/752 ... y-is-not-x
https://unix.stackexchange.com/question ... -was-found
https://stackoverflow.com/questions/977 ... cter-group
https://www.perlmonks.org/?node_id=229044/
https://stackoverflow.com/questions/234 ... ng-pattern