0

I am trying to extract HostName and Email address from text file using regex. These fields are optional. It is possible that in some cases only one field is available.

For example: if email address is not available is should extract only hostname and vice versa.

I got nearly working regex. Just not working for single case. see the regex in below link.

regex: ^.*(MAIL:(?<EMAIL>.*))(HOST:(?<HOSTNAME>.*))?

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

Note: I am not looking this for specific language.

Thanks

4
  • please, post the strings that you are working on and avoid external links Commented Feb 21, 2019 at 14:40
  • Maybe MAIL:(?<EMAIL>.*)|HOST:(?<HOSTNAME>.*) (demo)? Commented Feb 21, 2019 at 14:42
  • I just updated the link with that! regex101.com/r/SDOcIR/2 Commented Feb 21, 2019 at 14:44
  • Guys it fixed for 2nd line which was not working but broke all others. Now email field include both host and mail address. Commented Feb 21, 2019 at 14:50

1 Answer 1

1

Try Regex: (?:MAIL:(?<EMAIL>[^ ]+))|(?:HOST:(?<HOSTNAME>.*))

Demo

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

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.