0

DESCRIPTION:

I have a string with a word, a number, bracket, and a letter inside the bracket.

QUESTION:

I want to extract only the numbers with decimal and the bracket with a letter in it.

EXAMPLE:

, INC., 5.5(b) -------> 5.5(b)

Section 13.2(k)(ii) ---------> 13.2(k)(ii)

WBNEOGNOFD.)! 82.3(b)(k)(ix) -----------> 82.3(b)(k)(ix)

ATTEMPT I MADE:

Find the first number then the decimal, followed by '('. But, sometimes, its only 1 number and no brackets after the decimal.

SOLUTION I THINK WOULD SOLVE BUT I COULD NOT SOLVE IT:

curly brace repetition qualifiers {} to match exactly three alphabetic characters and exactly four numeric characters. I tried the answer given by Christian Dean to solve for my regex, but it did not give an accurate result. (Extract string with specific format)

4
  • 1
    When there are no brackets after the decimal, do you want a match or not? Commented Oct 8, 2018 at 15:21
  • 1
    please share the regex you tried Commented Oct 8, 2018 at 15:21
  • @CertainPerformance: Anything would work. To match it or not, unless it can identify that pattern. Commented Oct 8, 2018 at 15:23
  • @depperm: search('\d.\d{2}([a-zA-Z])', string). We use /d to find any digit, what do we use to identify a decimal, or a bracket? Commented Oct 8, 2018 at 15:26

1 Answer 1

1

To match digits with decimals followed by groups of ()s, you can use

\d+\.\d+(?:\(\w+\))+

https://regex101.com/r/wqYZr9/1

  • \d+\.\d+ - Match a decimal number
  • (?:\(\w+\))+ - Repeat a group of word characters in parentheses
Sign up to request clarification or add additional context in comments.

8 Comments

Is it possible to extract a single digit?
You mean, don't match decimal numbers or numbers greater than 9? I guess you could lookbehind for a space or the start of the string or something, something like (?<= )\d(?:\(\w+\))+ Not sure exactly what you're looking for
For example, using your regex, I could not extract if the string was "Article 7". Is it possible to extract that '7', if the string has no decimal and only a digit?
If the string contains only a single digit and you want to match that digit, just use \d
Yeah. But what if it needs either a single digit or a group of it (Just the way it is described above)?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.