Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

get only Parts from search Result?

Last post 07-30-2008, 7:58 AM by jprhamburg. 8 replies.
Sort Posts: Previous Next
  •  07-24-2008, 6:53 AM 44521

    get only Parts from search Result?

    Hi!

    My problem is want only get few parts from following search-result:

    This is my Source:

    ------------------------------------------------------------------------------------- 

                      $1207$ $1208$
                                                                                    e-mail: uerrt@fz-bssstel.de
                        

                                                                                 Borstel, den $4001$

                        

                         Patient:              Ruth, Jeter geb. 24.03.1986

                         Wohnort:              $1051$

                                               $1052$

                         Untersuchung am :     21.07.2008    

                        
                        

                        

                         Sehr geehrte Frau Kollegin, sehr geehrter Herr Kollege, 

    ------------------------------------------------------------------------

     I want get a Result as following: Rut21072008

    Rut= Patient:              Ruth, Jeter geb. 24.03.1986

    21072008= 21.07.2008  

    my previous syntax is: (?<=Patient:\s{1,})([a-zA-Z]{3})[./s]{0,}(?<=Untersuchung am :\s{1,})([0-9]{2}).([0-9]{2}).([0-9]{4})

    Can anybody help me?

    Thanks!
     

  •  07-24-2008, 11:59 AM 44531 in reply to 44521

    Re: get only Parts from search Result?

    Raw Match Pattern:
    (?is)Patient: *([a-z]{3}).*?Untersuchung am : *(\d{2})\.(\d{2})\.(\d{4})

    $matches Array:
    (
        [0] => Patient:              Ruth, Jeter geb. 24.03.1986

                         Wohnort:              $1051$

                                               $1052$

                         Untersuchung am :     21.07.2008
        [1] => Rut
        [2] => 21
        [3] => 07
        [4] => 2008
    )
     

    Note the groups 1 through 4.


  •  07-25-2008, 3:26 AM 44556 in reply to 44531

    Re: get only Parts from search Result?

    Thanks! Your Version is more nicer than my.

    But i cant work with c#-Logic, I have to solve this problem only with RegularExpression.

    Can i use backreferences in .NET-Regex to get only group 1 to 4?

    I have try to use backreferences but no change for me....

     

  •  07-25-2008, 1:16 PM 44576 in reply to 44556

    Re: get only Parts from search Result?

    Show your regex code if you want specific help, but for example in general:

    Regex re = new Regex(@"...");

    MatchCollection mc = re.Matches(yoursourcestring);

    foreach (Match m in mc)

    new Regex(@"...");

    MatchCollection mc = re.Matches(yoursourcestring);

    foreach (Match m in mc)

    foreach (Match m in mc)

    Console.WriteLine(m.Groups[1].Value);

    Console.WriteLine(m.Groups[2].Value);

    Console.WriteLine(m.Groups[3].Value);

    Console.WriteLine(m.Groups[4].Value);


  •  07-28-2008, 2:18 AM 44631 in reply to 44576

    Re: get only Parts from search Result?

    My Problem is that i cant use c# to solve my Problem!

    I can try it only with Regular Expression - Syntax...

    Because: I have a program to parse IdentifyNumbers, and a configuration-set to set regularExpression. I cant change this programm (to change logic in c#), i have to try solve this only with RegularExpressions 

  •  07-28-2008, 12:34 PM 44656 in reply to 44631

    Re: get only Parts from search Result?

    Then the pattern I posted is the answer:

    Raw Match Pattern:
    (?is)Patient: *([a-z]{3}).*?Untersuchung am : *(\d{2})\.(\d{2})\.(\d{4})

    If you can access them, your target data is in groups 1-4, if you can't access those groups in your app then I'm not sure how I can help.


  •  07-29-2008, 7:46 AM 44688 in reply to 44656

    Re: get only Parts from search Result?

    i have found following website:

    http://msdn.microsoft.com/en-us/library/ewy2t5e0(VS.71).aspx

    with  "Substitutions" it sould be working or not?

    but i dont understand this discription..  maybe you?
     

  •  07-30-2008, 1:06 AM 44729 in reply to 44688

    Re: get only Parts from search Result?

    Do I understand that you want to replace all of the source text with just the selected parts you pointed out?

    If so, then change ddrudiks pattern to be:

    (?is)(.*?)Patient: *([a-z]{3}).*?Untersuchung am : *(\d{2})\.(\d{2})\.(\d{4})(.*?)$

    and set the replacement string to be:

    $2$3$4$5

    This assumes that the "Patient....." test occurs only once in the whole pattern. If this is not true, then you will need to show us exactly where we should start and end each "Patient..." data.

    If not, then you will need to tell us exactly how we can find the start and end of the section you want replaced - perhaps you could give us several example records and not just one.

    Susan
     

  •  07-30-2008, 7:58 AM 44748 in reply to 44729

    Re: get only Parts from search Result?

    Thats my problem, i dont have a "replacement string", i can set only the "Match string"

    And I try to get only Rut27072008 with "match"

    Thank you for help, but now i have change my programm and add a replace-logic and give your Pattern and the Information "get only $1$2$3..." into

     

View as RSS news feed in XML