0

I need to extract following from below string using REGEX, can anyone help

String = "[payment is made within [ 10  ] Business Days  of its due date.]"

Output:

[ 10  ] Business Days
2
  • 1
    You need to specify what exactly are you looking for. Is is a substring containing a number of "Business Days"? Is it the string containing 2 words after number 10 in square brackets? Spaces are important too. Will there always be a space between number and brackets? Add more details. Commented Sep 29, 2018 at 18:31
  • If you just want to find that substring with varying number of days, it would be ([ [0-9]+ ] Business Days). Commented Sep 29, 2018 at 18:42

1 Answer 1

1

Please try this.

s/^\[payment is made within (\[ [0-9]* \]) Business Days.*$/\1 Business Days/
Sign up to request clarification or add additional context in comments.

10 Comments

can you try here - regexr.com... im trying above regex and it doesn't work
Maybe [0-9]+? Also I don't use regexp much, but is s/*/*/ a standard syntax or is it specific to sed?
It is working. I am using PCRE engine. Which one are you using?
Use this link regexr.com/40cfn. And then under tool, add following text- "\1 Business Days" without quotes. And use replace option.
@IcedLance It is specific to SED. But I feel it as good shorthand to write whenever somebody asks for regex.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.