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 3952310
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:50:07+00:00 2026-05-20T01:50:07+00:00

I’m trying to create a regex containing character set which can contain a period

  • 0

I’m trying to create a regex containing character set which can contain a period or colon but may not end with a period. So I want to mach a line saying "Lorem./: Ipsom dolor sit" but not "Lorem ipsum dolor sit."

This is what my current regex looks like, but it’s not working as it will match if the string ends on a period or colon:

/(\n{2,})([ \wåäöÅÄÖ,()%+\-:.]{2,75}[^.:])(\n{1,})/

I’m looking for headings in a huge, badly formatted plain text file. And the general pattern in this file is that a heading is always preceded by two newlines or more and always succeeded by one newline or more. Also a heading sometimes ends on a : but never on a . however they sometimes contain a . or :. Also they’re always 2-75 characters long and never preceded by another heading.

Any help would be greatly appreciated.

Edit: I realised that my explanation where quite bad and partly wrong thus updated this post.

  • 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-05-20T01:50:08+00:00Added an answer on May 20, 2026 at 1:50 am

    In general, if you want to match a string not ending in a dot, just add (?<!\.)$ to the end of the regex.

    This is a negative lookbehind assertion.

    In your special case, the match is supposed to continue after this, though, so we need a different approach:

    /\n{2,}([ \wåäöÅÄÖ,()%+\-:.]{2,75}(?<!\.))\n+/
    

    will match any line that

    • follows two or more newlines (\n{2,}),
    • consists only of 2 to 75 allowed characters ([ \wåäöÅÄÖ,()%+\-:.]),
    • doesn’t end in . ((?<!\.) – )
    • and is followed by at least one newline (\n+).

    EDIT:

    A new, expanded regex, trying to incorporate some of the logic discussed in the comments below; formatted as a verbose regex:

    preg_match_all(
        '/(?<=\n\n)   # Assert that there are two newlines before the current position
        ^             # Assert that we\'re at the start of a line
        (?![\d -]+$)  # Assert that the line consists not solely of digits, spaces and -s
                      # Assert that the line doesn\'t consist of two Uppercase Words
        (?!\s*\p{Lu}\p{L}*\s+\p{Lu}\p{L}*\s*$)
                      # Match 2-75 of the allowed characters
        [ \wåäöÅÄÖ,()%+\-:.]{2,75}
        (?<!\.)       # Assert that the last one isn\'t a dot
        $             # Assert position at the end of a line
        (?=\n)        # Assert that one newline follows.
        /mxu', 
        $subject, $result, PREG_PATTERN_ORDER);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,

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.