Wouldn’t having ‘\b’ on both sides match beginning AND end? It’s got the parenthesis for the ‘|’ in the wrong place.
Wouldn’t having ‘\b’ on both sides match beginning AND end? It’s got the parenthesis for the ‘|’ in the wrong place.
https://regex101.com/r/ZNQa9X/1
The generated regex is the same as
(\bdog\b)|(\bcat\b)
https://regex101.com/r/vTtEU4/1I’m currently trying to figure out how to match a word starting with dog without using
\bdog.*
because .*
would proceed to eat the rest of the line.So I was thinking I could say
\bdog[^\b]*
But that doesn’t work, it also ends up eating the rest of the line as well. \b(dog\S*)|(\S*cat)\b
You could also use a \B instead of a \S though there are different meanings there.https://regex101.com/r/sbpy8s/1
But this matches for example
dog.cat
as one single word.But I would like that it matches separately
dog
and cat
in this case.Likewise, I’d want for example
dogapple-bananacat
to be matched as two separate words dogapple
and bananacat
After a bit more reading online I thought that maybe the following regex would do what I want: \b(dog\p{L}*)|(\p{L}*cat)\b
https://regex101.com/r/1NT5Ie/1But that does not match
dog42
as a word.What I want is a way to include everything after dog that is not \b
And likewise everything preceding cat that is not \b
Edit: I think I’ve found it after reading https://stackoverflow.com/questions/4541573/what-are-non-wor...
(\bdog\w*)|(\w*cat\b)
Seems to behave exactly like I want.To me it feels like if 90% of $TASK content out there would be bad and people would struggle with it, then the AI-genrated $TASK output would be similarly flawed, be it regarding a programming language or something else.
As a silly example, consider how much bad legacy PHP code is out there and what the answers to some PHP questions could become because of that.
But it's still possible to get answers to simplistic problems reasonably fast, or at least get workable examples to then test and iterate upon, which can easily save some time.
\bdog\w\* (\bdog\w*)|(\w*cat\b)
Seems to behave exactly like I want.The regex I was expecting would be
"\\b(dog.*)|(.*cat)\\b"
The key point is to ask the code model. Part of what ChatGPT does is it appears to categorize the question and then may dispatch it to the code model. If you know you have a code question, asking the code model first would likely be more productive and less expensive.you regex will match the whole line up to cat.