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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:09:55+00:00 2026-06-18T14:09:55+00:00

I’d like to think I’m pretty good at regular expressions, but this one is

  • 0

I’d like to think I’m pretty good at regular expressions, but this one is stumping me. I’m trying to match a certain type of language used in National Weather Service forecast bulletins. I’m using Perl 5.16 on Windows. I have also tested using this online regex tester. Here is an example message:

...A SEVERE THUNDERSTORM WARNING REMAINS IN EFFECT UNTIL 1130 PM CST FOR CENTRAL LAMAR COUNTY... AT 1106 PM CST...NATIONAL WEATHER SERVICE METEOROLOGISTS WERE TRACKING A SEVERE THUNDERSTORM CAPABLE OF PRODUCING PING PONG BALL SIZE HAIL...AND DESTRUCTIVE WINDS IN EXCESS OF 70 MPH. THIS STORM WAS LOCATED NEAR BAXTERVILLE MOVING EAST AT 50 MPH. THE SEVERE THUNDERSTORM WILL BE NEAR... PURVIS BY 1115 PM CST... WEST HATTIESBURG BY 1120 PM CST...

And here is my regex:

/A SEVERE THUNDERSTORM.+?(?<hsize>QUARTER|GOLF BALL|PING PONG BALL|HALF DOLLAR)?.+?WINDS (?:IN EXCESS OF|OVER) (?<wmph>\d+) MPH.+WAS LOCATED (?:(?<dist>\d+) MILES (?<dir>\w+) OF|(?<near>NEAR)) (?<loc>[\w ]+).+MOVING (?<mdir>\w+) AT (?<mph>\d+) MPH/

The problem is that the hsize parameter always returns blank. I would like it to be optional but greedy, however it never matches. I tried making it nonoptional:

/A SEVERE THUNDERSTORM.+?(?<hsize>QUARTER|GOLF BALL|PING PONG BALL|HALF DOLLAR).+?WINDS (?:IN EXCESS OF|OVER) (?<wmph>\d+) MPH.+WAS LOCATED (?:(?<dist>\d+) MILES (?<dir>\w+) OF|(?<near>NEAR)) (?<loc>[\w ]+).+MOVING (?<mdir>\w+) AT (?<mph>\d+) MPH/

Which does cause it to match, which makes no sense to me. As you can see, I’ve already made the wildcards nongreedy, so I don’t see what’s happening.

  • 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-18T14:09:56+00:00Added an answer on June 18, 2026 at 2:09 pm

    You can change a bit of your regex to force the engine to search for the special text before resorting to match anything. Change this part of the regex:

    .+?(?<hsize>QUARTER|GOLF BALL|PING PONG BALL|HALF DOLLAR)?
    

    To:

    (?:.+?(?<hsize>QUARTER|GOLF BALL|PING PONG BALL|HALF DOLLAR)|.+?)
    

    The alternation will force the engine to exhaust all the possibility of finding a match with the special keywords (the first alternative), before go on to match anything (the 2nd alternative).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.