Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
As @ArtOfCode mentioned, it is not fully clear what you are trying to match. From the first line in your post, you are trying to extract THIS. THAT. out of THIS. THAT..OTHER . The following regex ...
Answer
#2: Post edited
- As @ArtOfCode mentioned, it is not fully clear what you are trying to match.
- From the first line in your post, you are trying to extract `THIS. THAT.` out of `THIS. THAT..OTHER `. The following regex achieves it:
`- >>> re.search('([A-Z]+\.\s?)+', 'THIS. THAT..OTHER ')
- <re.Match object; span=(0, 11), match='THIS. THAT.'>
`- However, from your title and your last paragraph, it sounds more like you are trying to extract `THIS. THAT.` out of `THIS. THAT. OTHER.`, with potential white spaces at the end. In that case, this other regex can be of use:
`- >>> re.search('(\s?[A-Z]+\.)+(?=(\s+[A-Z]+\.?\s?)\Z)', 'THIS. THAT. OTHER. ')
- <re.Match object; span=(0, 11), match='THIS. THAT.'>
`- If none of these expressions are what you are looking for, please clarify your question.
- As @ArtOfCode mentioned, it is not fully clear what you are trying to match.
- From the first line in your post, you are trying to extract `THIS. THAT.` out of `THIS. THAT..OTHER `. The following regex achieves it:
- ```
- >>> re.search('([A-Z]+\.\s?)+', 'THIS. THAT..OTHER ')
- <re.Match object; span=(0, 11), match='THIS. THAT.'>
- ```
- However, from your title and your last paragraph, it sounds more like you are trying to extract `THIS. THAT.` out of `THIS. THAT. OTHER.`, with potential white spaces at the end. In that case, this other regex can be of use:
- ```
- >>> re.search('(\s?[A-Z]+\.)+(?=(\s+[A-Z]+\.?\s?)\Z)', 'THIS. THAT. OTHER. ')
- <re.Match object; span=(0, 11), match='THIS. THAT.'>
- ```
- If none of these expressions are what you are looking for, please clarify your question.
#1: Initial revision
As @ArtOfCode mentioned, it is not fully clear what you are trying to match. From the first line in your post, you are trying to extract `THIS. THAT.` out of `THIS. THAT..OTHER `. The following regex achieves it: ` >>> re.search('([A-Z]+\.\s?)+', 'THIS. THAT..OTHER ') <re.Match object; span=(0, 11), match='THIS. THAT.'> ` However, from your title and your last paragraph, it sounds more like you are trying to extract `THIS. THAT.` out of `THIS. THAT. OTHER.`, with potential white spaces at the end. In that case, this other regex can be of use: ` >>> re.search('(\s?[A-Z]+\.)+(?=(\s+[A-Z]+\.?\s?)\Z)', 'THIS. THAT. OTHER. ') <re.Match object; span=(0, 11), match='THIS. THAT.'> ` If none of these expressions are what you are looking for, please clarify your question.