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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:20:13+00:00 2026-05-29T09:20:13+00:00

Is there a way to write a regular expression pattern that will create one

  • 0

Is there a way to write a regular expression pattern that will create one or two groups based on the input text. (i.e.)

// ONE
NSString *pattern = @""; ([0-9]+).([0-9]+)
NSString *inputText = @"ThisIs MyTest72.56String";
// OUTPUT match = 72.56, group1 = 72, group2 = 56

What I am trying to get is:

// TWO
NSString *pattern = @""; ([0-9]+).([0-9]+)
NSString *inputText = @"ThisIs MyTest72String";
// OUTPUT match = 72, group1 = 72, group2 = Empty

I was thinking I could use (?:) but that just removes the group

What I am after is:

Text = "ThisIs MyTest72String"
Match = 72
Group1 = 72
Group2 = Empty

Text = "ThisIs MyTest72.56String"
Match = 72.56
Group1 = 72
Group2 = 56

EDIT:

This sort of works, although I would like to get rid of the “S” in the initial match.

Pattern = ([0-9]+).([0-9]*)
Text = "ThisIs MyTest72String"
Match = 72S
Group1 = 72    //RangeAtIndex:1 {13,2}
Group2 = Empty //RangeAtIndex:2 {16,0}

Text = "ThisIs MyTest72.56String"
Match = 72.56
Group1 = 72
Group2 = 56

This is close, but in the case of “Empty” (Group2) I was expecting the rangeAtIndex:2 to equal NSNotFound. The docs say “The range {NSNotFound, 0} is returned if one of the capture groups did not participate in this particular match” does the group being empty not count as “Not participating”?

  • 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-29T09:20:14+00:00Added an answer on May 29, 2026 at 9:20 am

    Does this give you what you want?

    ([0-9]+)(?:\.([0-9]+))?
    

    I’ve escaped the decimal place (which you hadn’t, unsure if this is needed in your target language) and grouped the decimal and everything after it as a optional non captured group.

    Should just be a matter of checking for the existence of a second group.

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

Sidebar

Related Questions

I am trying to write a regular expression that will count the number of
Is there a convenient way to write a regex that will try to match
I am stumped trying to create an Emacs regular-expression that excludes groups. [^] excludes
I am trying to write a regular expression in Python that will match either
I'm trying to build a regular expression that will catch one of three patterns
Is there a way to write an enumeration that can be extended. I have
Is there a way to write log4j logging events to a log file that
I am trying to write a regular expression that matches only any of the
I need to write a regular expression that finds javascript files that match <anypath><slash>js<slash><anything>.js
I am trying to write a regular expression that can extract (possibly multiple) strings

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.