Pattern alternation on entire line

17 views
Skip to first unread message

Tom Robinson

unread,
Feb 10, 2020, 4:58:36 PM2/10/20
to BBEdit Talk
What have I missed here guys?

I want to match entire lines which are empty, contain a single ’s’, or contain ‘e’ and/or ‘h’ (in that order):

e
h
eh
s

ehs
he
x

The first 5 lines should match (including the empty line), last 3 shouldn’t.

But despite the caret anchor, my pattern is catching the ending of unwanted lines:

^s|(e?h?)$

Sam Hathaway

unread,
Feb 10, 2020, 5:12:23 PM2/10/20
to BBEdit Talk

^ and $ bind more tightly than |.

you want

^(s|(e?h?))$

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/1068812A-8CAC-4C07-94F6-E36B3CA756F7%40gmail.com.

Jean-Christophe Helary

unread,
Feb 10, 2020, 5:17:01 PM2/10/20
to bbe...@googlegroups.com
Tom,

The results are

[e]
[h]
[eh]
[s]
[]
ehs
h[e]
x
[]

So, it looks like the regex works like this:

^s

or

(e?h?)$

This one: ^s$|^(e?h?)$ seems to do what you want.


Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune


Tom Robinson

unread,
Feb 10, 2020, 5:31:29 PM2/10/20
to bbe...@googlegroups.com
Ah, thanks Sam!  (and Jean-Christophe)
Reply all
Reply to author
Forward
0 new messages