Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7765355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:08:48+00:00 2026-06-01T15:08:48+00:00

In: preferences = ‘Hello my name is paul. I hate puzzles.’ I want to

  • 0

In: preferences = 'Hello my name is paul. I hate puzzles.'
I want to extract Hello my name is paul.

In: preferences = 'Salutations my name is richard. I love pizza. I hate rain.'
I want to extract Salutations my name is richard. I love pizza.

In: preferences = 'Hi my name is bob. I enjoy ice cream.'
I want to extract Hi my name is bob. I enjoy ice cream.

In other words, I would like to

  • always discard preferences = '
  • discard any last sentence (delimited by .) that has the word hate in, if present.
  • discard the final '

My problem is that my regex stops at the first . and doesn’t extract the subsequent sentences.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:08:50+00:00Added an answer on June 1, 2026 at 3:08 pm

    You can achieve what you want using a regular expression:

    ^preferences\s*=\s*'(.*?\.)(?:[^.]*\bhate\b[^.]*\.)?'$
    

    That one isn’t too tricky:

    • (.*?\.) – Match your expected output, that will be captured in group $1. The pattern matches “sentences” (as you’ve defined), but lazily (*?), as few as it must.
    • (?:[^.]*\bhate\b[^.]*\.)? – optionally match the last sentence, but only if it contains “hate”. If it can match, and it is the last sentence, the matching engine will not backtrack, and the last sentence will not be included in the captured group.

    Here’s a working example in Rubular: http://www.rubular.com/r/qTuMmB3ySj
    (I’ve added \r\n in a few places, to avoid [^.] matching new lines)

    Honestly though, you can do better than a single regular expression here, if you can avoid it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've defined 2 preferences in the extension's config.xml file: <preference name=interval value=1800 readonly=false />
I have in preferences.xml following EditTextPreference: <EditTextPreference android:name=@string/pref_test android:defaultValue=0.6 android:inputType=numberDecimal android:key=editTestPref android:maxLength=5 android:summary= android:title=@string/pref_test
I want to use preferences, but I don't want to use it in xml.
When I created a preferences xml file (by right-clicking the project name, selecting |
I have some shared preferences (latitude, longitude) that I want to access from a
I want to store preferences which are Android version dependent (eg. User Agent string
I want to access iTunes user preferences such as playlists programmatically. I use to
Preferences is bound to command+, by default. Suppose I want to add an additional
Preferences objects present a way to store arbitrary data into Rally which can be
Personal preferences aside, is there an optimal tab size (2 spaces? 3 spaces? 8

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.