0

I had like to pass the following string via Regex to extract the domain name and the numeric value next to ms.

stackoverflow.com : [0], 96 bytes, 223 ms (223 avg, 0% loss)

I need:

stackoverflow.com , 223

Any help will be much appreciated.

2
  • What did you try? Please share. Then, we'll know better what you actually need: an array, or just separate values, 1 regex or 2... Commented Jul 21, 2015 at 7:51
  • Did you try anything before posting? Commented Jul 21, 2015 at 7:51

3 Answers 3

2

Use following regex:

(\w+\.[a-zA-Z]{2,3}).+?(\d+)\s+ms

Explanation

  1. (): Capturing group
  2. \w+: Match any alphanumeric characters any number of times
  3. \.: Match . literal
  4. [a-zA-Z]{2,3}: Match the two or three alphabets
  5. .+?: Matches any characters except linebreak
  6. \d+: Matches any number of digits

RegEx101 Demo

Sign up to request clarification or add additional context in comments.

Comments

1

the following seems to work

(\w+\.\w+) : .*, ([0-9]+) ms

Tested here

Comments

1

Try this:

(\w+\.[a-zA-Z]{2,3}).+?(\d+)\s+ms

Should work.

Demo: https://regex101.com/r/qI0xN6/1

Comments

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.