0

Any ideas on how could I get the values from the labeled below text using REGEX on Java Platform. If my regex search was involved the two words of "Demo and Name", I could get the line of "Name: John Doe". If my regex search was involved the two words of "Demo and Address", I could get the value of "Address: Home".

Comment Section

    Comment: This is the comment for Comment Section
    Another Field: This is for another field

Another Comment

    Comment: This is comment for another comment

Demo

    Name: John Doe
    Address: Home
5
  • What are you wanting? Commented Mar 31, 2014 at 14:28
  • 1
    It's really unclear what you want to achieve. Please elaborate. Commented Mar 31, 2014 at 14:35
  • What I want is to get the line of word when having a search on the text using REGEX. Just imagine that those text above was written on XML format. So, If I want to get the "John Doe", The targeting node is Demo->Name. Something like that, but I want it on REGEX. Commented Mar 31, 2014 at 14:35
  • @NappaTheSaiyan Can i achieve this process by using the REGEX? Because Im trying to use the look behind, look ahead but still no luck. Commented Mar 31, 2014 at 14:51
  • @Mark refer to my answer Commented Mar 31, 2014 at 14:54

1 Answer 1

1

This pattern works for name

Demo\s*|.*Name: (.*)

Test it here http://regexpal.com/

If you are using Java you will most likely be reading the input file one line at a time. If that is the case you need to set a flag when Demo pops up then check for a line containing "NAME:". Set flag off when closing DEMO tag pops up.

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

2 Comments

the patterns works fine, but how could I get the value of "Name: John Doe" like what has been highlighted on the sample runner
Anything between () is captured which means in this case "John Doe" will be captured. If you want "NAME: John Doe" then move the start of the parenthesis to before "Name"

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.